Skip to content

Commit

Permalink
Hotfix(server): 병원 객체를 리턴하는 형식 변경
Browse files Browse the repository at this point in the history
- converHospital()을 통해 snake_case로 된 키의 이름을 caemlCase로 변경
  • Loading branch information
hwna00 committed Oct 6, 2023
1 parent 6aa78fd commit 3747714
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
11 changes: 5 additions & 6 deletions packages/apps/doctor/src/views/SignUp/SignUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ const SignUp = function () {

const onSearchFieldClick = useCallback(async () => {
const hospitalName = getValues('hospital');
if (!hospitalName) {
if (hospitalName !== '') {
const { data } = await getHospitals(hospitalName);

if (data.length === 0) {
// TODO: webOS.notification 전송
if (data.isSuccess) {
setHospitals(data.hospitals);
} else {
setHospitals(data);
// TODO: webOS.notification 전송
}
}
}, [getValues]);
Expand Down Expand Up @@ -165,10 +165,9 @@ const SignUp = function () {
>
{hospitals.map(hospital => {
return (
// TODO: key를 id에서 ykiho로 변경해야 함
<HStack
as={'li'}
key={hospital.id}
key={hospital.hospitalId}
padding={'4'}
border={'1px'}
borderColor={'primary.200'}
Expand Down
40 changes: 21 additions & 19 deletions packages/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
getNaverAuthApiUri,
} = require('./controllers/authController');
const pool = require('./config/db');
const convertHospital = require('./utils/convertHospital');

require('dotenv').config();

Expand Down Expand Up @@ -100,15 +101,15 @@ const readUser = async function (req, res) {
} else {
return res.json({
result: convertUser(rows[0]),
isSucess: true,
isSuccess: true,
code: 200,
message: '유저 조회 성공',
});
}
} catch (err) {
if (err.message === 'User not found') {
return res.json({
isSucess: false,
isSuccess: false,
code: 404,
message: '유저를 찾을 수 없습니다.',
});
Expand All @@ -123,7 +124,7 @@ const readUser = async function (req, res) {
}
} catch (err) {
return res.json({
isSucess: false,
isSuccess: false,
code: 500,
message: '데이터베이스 연결 실패',
});
Expand Down Expand Up @@ -154,7 +155,7 @@ const createAppointment = async function (req, res) {
await createAppointmentQuery(connection, data);

return res.json({
isSucess: true,
isSuccess: true,
code: 201,
message: '예약정보 생성 성공',
});
Expand All @@ -169,7 +170,7 @@ const createAppointment = async function (req, res) {
}
} catch (err) {
return res.json({
isSucess: false,
isSuccess: false,
code: 500,
message: '데이터베이스 연결 실패',
});
Expand Down Expand Up @@ -214,7 +215,7 @@ const updateUser = async function (req, res) {
await updateUserQuery(connection, uid, data);

return res.json({
isSucess: true,
isSuccess: true,
code: 204,
message: '유저 업데이트 성공',
});
Expand All @@ -229,7 +230,7 @@ const updateUser = async function (req, res) {
}
} catch (err) {
return res.json({
isSucess: false,
isSuccess: false,
code: 500,
message: '데이터베이스 연결 실패',
});
Expand Down Expand Up @@ -258,15 +259,15 @@ const readUserAppointment = async function (req, res) {
} else {
return res.json({
result: rows,
isSucess: true,
isSuccess: true,
code: 200,
message: '유저 예약정보 조회 성공',
});
}
} catch (err) {
if (err.message === 'Appointment not found') {
return res.json({
isSucess: false,
isSuccess: false,
code: 404,
message: '예약정보를 찾을 수 없습니다.',
});
Expand All @@ -281,7 +282,7 @@ const readUserAppointment = async function (req, res) {
}
} catch (err) {
return res.json({
isSucess: false,
isSuccess: false,
code: 500,
message: '데이터베이스 연결 실패',
});
Expand Down Expand Up @@ -345,15 +346,15 @@ const readAppointments = async function (req, res) {
} else {
return res.json({
result: classifiedRows,
isSucess: true,
isSuccess: true,
code: 200,
message: '예약정보 조회 성공',
});
}
} catch (err) {
if (err.message === 'Appointments not found') {
return res.json({
isSucess: false,
isSuccess: false,
code: 404,
message: '예약정보를 찾을 수 없습니다.',
});
Expand All @@ -368,7 +369,7 @@ const readAppointments = async function (req, res) {
}
} catch (err) {
return res.json({
isSucess: false,
isSuccess: false,
code: 500,
message: '데이터베이스 연결 실패',
});
Expand Down Expand Up @@ -397,7 +398,7 @@ const updateAppointment = async function (req, res) {
await updateAppointmentQuery(connection, appointmentId, data);

return res.json({
isSucess: true,
isSuccess: true,
code: 204,
message: '예약정보 업데이트 성공',
});
Expand All @@ -412,7 +413,7 @@ const updateAppointment = async function (req, res) {
}
} catch (err) {
return res.json({
isSucess: false,
isSuccess: false,
code: 500,
message: '데이터베이스 연결 실패',
});
Expand Down Expand Up @@ -488,17 +489,18 @@ const readHospitals = async function (req, res) {
if (rows.length === 0) {
throw Error('Hospital not found');
} else {
const hospitals = rows.map(row => convertHospital(row));
return res.json({
Hospitals: rows,
isSucess: true,
hospitals,
isSuccess: true,
code: 200,
message: '병원 조회 성공',
});
}
} catch (err) {
if (err.message === 'Hospital not found') {
return res.json({
isSucess: false,
isSuccess: false,
code: 404,
message: '병원을 찾을 수 없습니다.',
});
Expand All @@ -513,7 +515,7 @@ const readHospitals = async function (req, res) {
}
} catch (err) {
return res.json({
isSucess: false,
isSuccess: false,
code: 500,
message: '데이터베이스 연결 실패',
});
Expand Down
9 changes: 9 additions & 0 deletions packages/server/utils/convertHospital.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = hospitalFromDB => {
const { hospital_id, ...rest } = hospitalFromDB;
const hospital = {
hospitalId: hospital_id,
...rest,
};

return hospital;
};

0 comments on commit 3747714

Please sign in to comment.