-
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
Showing
1 changed file
with
60 additions
and
59 deletions.
There are no files selected for viewing
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,76 +1,77 @@ | ||
import { userValidation } from './validations'; | ||
import axios from 'axios'; | ||
import { userValidation } from "./validations"; | ||
import axios from "axios"; | ||
|
||
export const getAllUsers = async () => { | ||
try { | ||
await axios.get(`${process.env.REACT_APP_API_URL}/users`).then((res) => { | ||
return res.data; | ||
}); | ||
} catch (error) { | ||
throw new Error(error.message); | ||
} | ||
try { | ||
const result = await axios.get(`${process.env.REACT_APP_API_URL}/users`); | ||
return result.data; | ||
} catch (error) { | ||
throw new Error(error.message); | ||
} | ||
}; | ||
|
||
export const getOneUser = async (studentId) => { | ||
try { | ||
await axios | ||
.get(`${process.env.REACT_APP_API_URL}/users/${studentId}`) | ||
.then((res) => { | ||
return res.data; | ||
}); | ||
} catch (error) { | ||
throw new Error(error.message); | ||
} | ||
try { | ||
const result = await axios.get( | ||
`${process.env.REACT_APP_API_URL}/users/${studentId}` | ||
); | ||
return result.data; | ||
} catch (error) { | ||
throw new Error(error.message); | ||
} | ||
}; | ||
|
||
export const addUser = async ( | ||
studentId, | ||
password, | ||
major, | ||
name, | ||
role, | ||
degree, | ||
comment | ||
studentId, | ||
password, | ||
major, | ||
name, | ||
role, | ||
degree, | ||
comment | ||
) => { | ||
try { | ||
const body = { | ||
studentId, | ||
password, | ||
major, | ||
name, | ||
role, | ||
degree, | ||
comment, | ||
}; | ||
if (!userValidation(body)) | ||
throw Error('유효성 검사에서 통과하지 못했습니다.'); | ||
await axios | ||
.post(`${process.env.REACT_APP_API_URL}/users`, body) | ||
.then((res) => { | ||
return res.data; | ||
}); | ||
} catch (error) { | ||
throw new Error(error); | ||
} | ||
try { | ||
const body = { | ||
studentId, | ||
password, | ||
major, | ||
name, | ||
role, | ||
degree, | ||
comment, | ||
}; | ||
if (!userValidation(body)) | ||
throw Error("유효성 검사에서 통과하지 못했습니다."); | ||
const res = await axios.post( | ||
`${process.env.REACT_APP_API_URL}/users`, | ||
body | ||
); | ||
return res.data; | ||
} catch (error) { | ||
throw new Error(error); | ||
} | ||
}; | ||
|
||
export const getUser = async (studentId) => { | ||
try { | ||
await axios.get(`${process.env.REACT_APP_API_URL}/users/${studentId}`).then((res) => { | ||
return res.data; | ||
}); | ||
} catch (error) { | ||
throw new Error(error.message); | ||
} | ||
try { | ||
const result = await axios.get( | ||
`${process.env.REACT_APP_API_URL}/users/${studentId}` | ||
); | ||
return result.data; | ||
} catch (error) { | ||
throw new Error(error.message); | ||
} | ||
}; | ||
|
||
export const updateUser = async (id, properties) => { | ||
try { | ||
try { | ||
const body = properties; | ||
await axios.patch(`${process.env.REACT_APP_API_URL}/users/${id}`, body).then((res) => { | ||
return res.data; | ||
}); | ||
} catch (error) { | ||
throw new Error(error.message); | ||
} | ||
const result = await axios.patch( | ||
`${process.env.REACT_APP_API_URL}/users/${id}`, | ||
body | ||
); | ||
return result.data; | ||
} catch (error) { | ||
throw new Error(error.message); | ||
} | ||
}; |