Skip to content

Commit

Permalink
fix: api function return
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonski committed Jul 21, 2023
1 parent 2c7ef4c commit 95258eb
Showing 1 changed file with 60 additions and 59 deletions.
119 changes: 60 additions & 59 deletions src/api/users.js
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);
}
};

0 comments on commit 95258eb

Please sign in to comment.