diff --git a/package-lock.json b/package-lock.json index 8d22ab0..0069159 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,6 @@ "requires": true, "packages": { "": { - "name": "qr-checkin-frontend", "version": "0.1.0", "dependencies": { "@blackbox-vision/react-qr-reader": "^5.0.0", diff --git a/src/api/auth.js b/src/api/auth.js index 19b28d2..d553582 100644 --- a/src/api/auth.js +++ b/src/api/auth.js @@ -1,142 +1,42 @@ -import axios from 'axios'; -import { userValidation } from './validations'; +import axios from "axios"; axios.defaults.withCredentials = true; export const login = async (studentId, password) => { - try { - const result = await axios.post( - `${process.env.REACT_APP_API_URL}/auth/login`, + try { + const result = await axios.post( + `${process.env.REACT_APP_API_URL}/auth/login`, - { - studentId: studentId, - password: password, - } - ); + { + studentId: studentId, + password: password, + } + ); - return result; - } catch (error) { - throw new Error(error.message); - } + return result; + } catch (error) { + throw new Error(error.message); + } }; export const logout = async () => { - try { - const result = await axios.post( - `${process.env.REACT_APP_API_URL}/auth/logout` - ); - return result; - } catch (error) { - throw new Error(error.message); - } + try { + const result = await axios.post( + `${process.env.REACT_APP_API_URL}/auth/logout` + ); + return result; + } catch (error) { + throw new Error(error.message); + } }; export const verify = async () => { - try { - const result = await axios.get( - `${process.env.REACT_APP_API_URL}/auth/verify` - ); - return result; - } catch (error) { - throw new Error(error.message); - } -}; - -export const getAllUsers = async () => { - try { - const result = await axios.get(`${process.env.REACT_APP_API_URL}/auth`); - return result.data.data.users; - } catch (error) { - throw new Error(error.message); - } -}; - -export const getOneUser = async (studentId) => { - try { - const result = await axios.get( - `${process.env.REACT_APP_API_URL}/auth/${studentId}` - ); - console.log(result) - return result.data.data.user; - } catch (error) { - throw new Error(error.message); - } -}; - -export const addUser = async ( - studentId, - password, - major, - name, - role, - degree -) => { - try { - const body = { - studentId, - password, - major, - name, - role, - degree, - isCheckedIn: false, - }; - if (!userValidation(body)) - throw Error('유효성 검사에서 통과하지 못했습니다.'); - const result = axios.post( - `${process.env.REACT_APP_API_URL}/auth/register`, - - body - ); - return result; - } catch (error) { - throw new Error(error); - } -}; - -export const getUser = async (studentId) => { - try { - const result = await axios.get( - `${process.env.REACT_APP_API_URL}/auth/${studentId}` - ); - return result.data.data.user; - } catch (error) { - throw new Error(error.message); - } -}; - -export const updateUser = async (id, properties) => { - try { - const body = properties; - const result = axios.patch( - `${process.env.REACT_APP_API_URL}/auth/${id}`, - - body - ); - return result; - } catch (error) { - throw new Error(error.message); - } -}; - -export const resetCheckInAll = async () => { - try { - const result = await axios.patch( - `${process.env.REACT_APP_API_URL}/auth/checkin` - ); - return result; - } catch (error) { - throw new Error(error.message); - } -}; - -export const resetCheckInOne = async (id) => { - try { - const result = await axios.patch( - `${process.env.REACT_APP_API_URL}/auth/checkin/${id}` - ); - return result; - } catch (error) { - throw new Error(error.message); - } + try { + const result = await axios.get( + `${process.env.REACT_APP_API_URL}/auth/verify` + ); + return result; + } catch (error) { + throw new Error(error.message); + } }; diff --git a/src/api/users.js b/src/api/users.js new file mode 100644 index 0000000..ddb67e0 --- /dev/null +++ b/src/api/users.js @@ -0,0 +1,79 @@ +import { userValidation } from "./validations"; +import axios from "axios"; + +export const getAllUsers = async () => { + try { + const result = await axios.get(`${process.env.REACT_APP_API_URL}/users`); + return result.data.data.users; + } catch (error) { + throw new Error(error.message); + } +}; + +export const getOneUser = async (studentId) => { + try { + const result = await axios.get( + `${process.env.REACT_APP_API_URL}/users/${studentId}` + ); + console.log(result); + return result.data.data.user; + } catch (error) { + throw new Error(error.message); + } +}; + +export const addUser = async ( + studentId, + password, + major, + name, + role, + degree, + comment +) => { + try { + const body = { + studentId, + password, + major, + name, + role, + degree, + comment, + }; + if (!userValidation(body)) + throw Error("유효성 검사에서 통과하지 못했습니다."); + const result = axios.post( + `${process.env.REACT_APP_API_URL}/users/register`, + body + ); + return result; + } catch (error) { + throw new Error(error); + } +}; + +export const getUser = async (studentId) => { + try { + const result = await axios.get( + `${process.env.REACT_APP_API_URL}/users/${studentId}` + ); + return result.data.data.user; + } catch (error) { + throw new Error(error.message); + } +}; + +export const updateUser = async (id, properties) => { + try { + const body = properties; + const result = axios.patch( + `${process.env.REACT_APP_API_URL}/users/${id}`, + + body + ); + return result; + } catch (error) { + throw new Error(error.message); + } +}; diff --git a/src/api/validations.js b/src/api/validations.js index 8009e9c..307d888 100644 --- a/src/api/validations.js +++ b/src/api/validations.js @@ -1,4 +1,4 @@ -import { getAllUsers } from "./auth"; +import { getAllUsers } from "./users"; export const userValidation = async (body) => { //1. 학번이 유일한지 확인 diff --git a/src/components/admin/AdminTable.js b/src/components/admin/AdminTable.js index d38c4af..af76058 100644 --- a/src/components/admin/AdminTable.js +++ b/src/components/admin/AdminTable.js @@ -8,15 +8,8 @@ import TableHead from "@mui/material/TableHead"; import TableRow from "@mui/material/TableRow"; import Paper from "@mui/material/Paper"; import Button from "@mui/material/Button"; -import styled from "@emotion/styled"; -import { getAllUsers, resetCheckInAll, resetCheckInOne } from "../../api/auth"; - -const FlexBox = styled.div` - display: flex; - margin-top: 10px; - justify-content: flex-end; -`; +import { getAllUsers } from "../../api/users"; export default function UserTable() { const [users, setUsers] = useState([]); @@ -39,8 +32,7 @@ export default function UserTable() { 전공 학위 권한 - 체크인 여부 - 체크인 초기화 + 코멘트 수정 @@ -51,19 +43,8 @@ export default function UserTable() { {row.name} {row.major} {row.degree} + {row.comment} {row.role} - {row.isCheckedIn ? 1 : 0} - - - - ); } diff --git a/src/components/admin/UserForm.js b/src/components/admin/UserForm.js index 8568b33..2e9f1ea 100644 --- a/src/components/admin/UserForm.js +++ b/src/components/admin/UserForm.js @@ -4,7 +4,7 @@ import Button from "@mui/material/Button"; import TextField from "@mui/material/TextField"; import Container from "@mui/material/Container"; import Box from "@mui/material/Box"; -import { addUser, updateUser, getOneUser } from "../../api/auth"; +import { addUser, updateUser, getOneUser } from "../../api/users"; import styled from "@emotion/styled"; import SelectLabels from "./UserForm_SelectBox";