-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1582b5
commit e23aa07
Showing
6 changed files
with
113 additions
and
165 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters