박권수

feat. api return type change

...@@ -155,7 +155,9 @@ exports.getBottleInfo = async(ctx) => { ...@@ -155,7 +155,9 @@ exports.getBottleInfo = async(ctx) => {
155 .populate('bmId'); 155 .populate('bmId');
156 156
157 ctx.status = 200; 157 ctx.status = 200;
158 - ctx.body = takeMedicineHist; 158 + ctx.body = {
159 + takeMedicineHist,
160 + };
159 161
160 } else { 162 } else {
161 ctx.status = 404; 163 ctx.status = 404;
...@@ -371,7 +373,9 @@ exports.getHubsBottleList = async(ctx) => { ...@@ -371,7 +373,9 @@ exports.getHubsBottleList = async(ctx) => {
371 } 373 }
372 374
373 ctx.status = 200; 375 ctx.status = 200;
374 - ctx.body = bottleList; 376 + ctx.body = {
377 + bottleList,
378 + };
375 379
376 }; 380 };
377 381
...@@ -399,6 +403,8 @@ exports.getAllBottleList = async ctx => { ...@@ -399,6 +403,8 @@ exports.getAllBottleList = async ctx => {
399 })); 403 }));
400 404
401 ctx.status = 200; 405 ctx.status = 200;
402 - ctx.body = bottleList; 406 + ctx.body = {
407 + bottleList
408 + };
403 409
404 }; 410 };
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -47,7 +47,9 @@ exports.getDoctorsInfo = async ctx => { ...@@ -47,7 +47,9 @@ exports.getDoctorsInfo = async ctx => {
47 } 47 }
48 48
49 ctx.status = 200; 49 ctx.status = 200;
50 - ctx.body = doctorInfo.info; 50 + ctx.body = {
51 + doctorInfo : doctorInfo.info
52 + };
51 53
52 }; 54 };
53 55
...@@ -68,19 +70,24 @@ exports.getPatientList = async ctx => { ...@@ -68,19 +70,24 @@ exports.getPatientList = async ctx => {
68 const user = await User.findByUserId(userId); 70 const user = await User.findByUserId(userId);
69 if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') { 71 if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') {
70 ctx.status = 403; 72 ctx.status = 403;
73 + ctx.body = {
74 + error : '권한 없는 유저',
75 + };
71 return; 76 return;
72 } 77 }
73 78
74 const managePatientIdList = await PatientInfo.findAllByDoctorIdAndUseYn(userId, 'Y'); 79 const managePatientIdList = await PatientInfo.findAllByDoctorIdAndUseYn(userId, 'Y');
75 80
76 - const result = []; 81 + const patientList = [];
77 await Promise.all(managePatientIdList.map(async patient => { 82 await Promise.all(managePatientIdList.map(async patient => {
78 const patientProfile = await Profile.findByUserId(patient.patientId); 83 const patientProfile = await Profile.findByUserId(patient.patientId);
79 - result.push(patientProfile); 84 + patientList.push(patientProfile);
80 })); 85 }));
81 86
82 ctx.status = 200; 87 ctx.status = 200;
83 - ctx.body = result; 88 + ctx.body = {
89 + patientList,
90 + };
84 91
85 }; 92 };
86 93
...@@ -101,6 +108,9 @@ exports.getPatientDetail = async ctx => { ...@@ -101,6 +108,9 @@ exports.getPatientDetail = async ctx => {
101 const user = await User.findByUserId(userId); 108 const user = await User.findByUserId(userId);
102 if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') { 109 if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') {
103 ctx.status = 403; 110 ctx.status = 403;
111 + ctx.body = {
112 + error : '권한 없는 사용자',
113 + };
104 return; 114 return;
105 } 115 }
106 116
...@@ -108,12 +118,18 @@ exports.getPatientDetail = async ctx => { ...@@ -108,12 +118,18 @@ exports.getPatientDetail = async ctx => {
108 const patient = await User.findByUserId(patientId); 118 const patient = await User.findByUserId(patientId);
109 if(!patient || patient.useYn !== 'Y') { 119 if(!patient || patient.useYn !== 'Y') {
110 ctx.status = 404; 120 ctx.status = 404;
121 + ctx.body = {
122 + error : '존재하지 않는 유저',
123 + };
111 return; 124 return;
112 } 125 }
113 126
114 const isDoctorsPatient = await PatientInfo.findByPatientIdAndDoctorIdAndUseYn(patientId, userId, 'Y'); 127 const isDoctorsPatient = await PatientInfo.findByPatientIdAndDoctorIdAndUseYn(patientId, userId, 'Y');
115 if(!isDoctorsPatient) { 128 if(!isDoctorsPatient) {
116 ctx.status = 403; 129 ctx.status = 403;
130 + ctx.body = {
131 + error : '접근 권한 없는 환자',
132 + };
117 return; 133 return;
118 } 134 }
119 135
...@@ -137,9 +153,10 @@ exports.getPatientDetail = async ctx => { ...@@ -137,9 +153,10 @@ exports.getPatientDetail = async ctx => {
137 })); 153 }));
138 154
139 const bottleList = await Promise.all(reqUserBmList.map(async bottleMedicine => { 155 const bottleList = await Promise.all(reqUserBmList.map(async bottleMedicine => {
140 - const { dosage, regDtm, medicineId } = bottleMedicine; 156 + const { bottleId, dosage, regDtm, medicineId } = bottleMedicine;
141 const medicine = await Medicine.findOne({ medicineId }); 157 const medicine = await Medicine.findOne({ medicineId });
142 return { 158 return {
159 + bottleId,
143 dosage, 160 dosage,
144 regDtm, 161 regDtm,
145 medicine, 162 medicine,
...@@ -208,6 +225,7 @@ exports.getBottleDetail = async ctx => { ...@@ -208,6 +225,7 @@ exports.getBottleDetail = async ctx => {
208 }).sort({ fdbDtm : 'desc' }); 225 }).sort({ fdbDtm : 'desc' });
209 226
210 const result = { 227 const result = {
228 + bottleId,
211 medicine, 229 medicine,
212 takeMedicineHist, 230 takeMedicineHist,
213 feedbackList, 231 feedbackList,
...@@ -235,6 +253,9 @@ exports.writeReqPatientReport = async ctx => { ...@@ -235,6 +253,9 @@ exports.writeReqPatientReport = async ctx => {
235 const user = await User.findByUserId(userId); 253 const user = await User.findByUserId(userId);
236 if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') { 254 if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') {
237 ctx.status = 403; 255 ctx.status = 403;
256 + ctx.body = {
257 + error : '권한 없는 유저',
258 + };
238 return; 259 return;
239 } 260 }
240 261
...@@ -242,12 +263,18 @@ exports.writeReqPatientReport = async ctx => { ...@@ -242,12 +263,18 @@ exports.writeReqPatientReport = async ctx => {
242 const patient = await User.findByUserId(patientId); 263 const patient = await User.findByUserId(patientId);
243 if(!patient || patient.useYn !== 'Y') { 264 if(!patient || patient.useYn !== 'Y') {
244 ctx.status = 404; 265 ctx.status = 404;
266 + ctx.body = {
267 + error : '존재하지 않는 유자',
268 + };
245 return; 269 return;
246 } 270 }
247 271
248 const patientInfo = await PatientInfo.findByPatientIdAndDoctorIdAndUseYn(patientId, userId, 'Y'); 272 const patientInfo = await PatientInfo.findByPatientIdAndDoctorIdAndUseYn(patientId, userId, 'Y');
249 if(!patientInfo) { 273 if(!patientInfo) {
250 ctx.status = 404; 274 ctx.status = 404;
275 + ctx.body = {
276 + error : '접근 권한 없는 환자',
277 + };
251 return; 278 return;
252 } 279 }
253 280
...@@ -327,6 +354,9 @@ exports.searchPatientById = async ctx => { ...@@ -327,6 +354,9 @@ exports.searchPatientById = async ctx => {
327 const user = await User.findByUserId(userId); 354 const user = await User.findByUserId(userId);
328 if(!user || user.userTypeCd !== 'DOCTOR') { 355 if(!user || user.userTypeCd !== 'DOCTOR') {
329 ctx.status = 403; 356 ctx.status = 403;
357 + ctx.body = {
358 + error : '권한 없는 유저',
359 + };
330 return; 360 return;
331 } 361 }
332 362
...@@ -334,6 +364,9 @@ exports.searchPatientById = async ctx => { ...@@ -334,6 +364,9 @@ exports.searchPatientById = async ctx => {
334 const patient = await User.findByUserId(patientId); 364 const patient = await User.findByUserId(patientId);
335 if(!patient || patient.useYn !== 'Y') { 365 if(!patient || patient.useYn !== 'Y') {
336 ctx.status = 404; 366 ctx.status = 404;
367 + ctx.body = {
368 + error : '존재하지 않는 회원',
369 + };
337 return; 370 return;
338 } 371 }
339 372
...@@ -363,6 +396,9 @@ exports.registerNewPatient = async ctx => { ...@@ -363,6 +396,9 @@ exports.registerNewPatient = async ctx => {
363 const user = await User.findByUserId(userId); 396 const user = await User.findByUserId(userId);
364 if(!user || user.userTypeCd !== 'DOCTOR') { 397 if(!user || user.userTypeCd !== 'DOCTOR') {
365 ctx.status = 403; 398 ctx.status = 403;
399 + ctx.body = {
400 + error : '권한 없는 유저',
401 + };
366 return; 402 return;
367 } 403 }
368 404
...@@ -370,12 +406,18 @@ exports.registerNewPatient = async ctx => { ...@@ -370,12 +406,18 @@ exports.registerNewPatient = async ctx => {
370 const patient = await User.findByUserId(patientId); 406 const patient = await User.findByUserId(patientId);
371 if(!patient || patient.useYn !== 'Y') { 407 if(!patient || patient.useYn !== 'Y') {
372 ctx.status = 404; 408 ctx.status = 404;
409 + ctx.body = {
410 + error : '존재하지 않는 유저',
411 + };
373 return; 412 return;
374 } 413 }
375 414
376 const isExistPatientInfo = await PatientInfo.findByPatientIdAndDoctorId(patientId, userId); 415 const isExistPatientInfo = await PatientInfo.findByPatientIdAndDoctorId(patientId, userId);
377 if(isExistPatientInfo) { 416 if(isExistPatientInfo) {
378 ctx.status = 403; 417 ctx.status = 403;
418 + ctx.body = {
419 + error : '이미 등록된 환자이거나, 등록 요청 대기중인 환자',
420 + };
379 return; 421 return;
380 } 422 }
381 423
...@@ -410,6 +452,9 @@ exports.removeReqPatient = async ctx => { ...@@ -410,6 +452,9 @@ exports.removeReqPatient = async ctx => {
410 const user = await User.findByUserId(userId); 452 const user = await User.findByUserId(userId);
411 if(!user || user.userTypeCd !== 'DOCTOR') { 453 if(!user || user.userTypeCd !== 'DOCTOR') {
412 ctx.status = 403; 454 ctx.status = 403;
455 + ctx.body = {
456 + error : '권한 없는 유저',
457 + };
413 return; 458 return;
414 } 459 }
415 460
...@@ -417,12 +462,18 @@ exports.removeReqPatient = async ctx => { ...@@ -417,12 +462,18 @@ exports.removeReqPatient = async ctx => {
417 const patient = await User.findByUserId(patientId); 462 const patient = await User.findByUserId(patientId);
418 if(!patient || patient.useYn !== 'Y') { 463 if(!patient || patient.useYn !== 'Y') {
419 ctx.status = 404; 464 ctx.status = 404;
465 + ctx.body = {
466 + error : '존재하지 않는 회원',
467 + };
420 return; 468 return;
421 } 469 }
422 470
423 const patientInfo = await PatientInfo.findByPatientIdAndDoctorIdAndUseYn(patientId, userId, 'Y'); 471 const patientInfo = await PatientInfo.findByPatientIdAndDoctorIdAndUseYn(patientId, userId, 'Y');
424 if(!patientInfo) { 472 if(!patientInfo) {
425 ctx.status = 404; 473 ctx.status = 404;
474 + ctx.body = {
475 + error : '등록되지 않은 환자',
476 + };
426 return; 477 return;
427 } 478 }
428 479
......
...@@ -44,7 +44,7 @@ exports.hubConnect = async (ctx) => { ...@@ -44,7 +44,7 @@ exports.hubConnect = async (ctx) => {
44 await hub.save(); 44 await hub.save();
45 45
46 ctx.status = 201; 46 ctx.status = 201;
47 - ctx.body = hub; 47 +
48 }; 48 };
49 49
50 exports.getHubList = async(ctx) => { 50 exports.getHubList = async(ctx) => {
...@@ -69,7 +69,9 @@ exports.getHubList = async(ctx) => { ...@@ -69,7 +69,9 @@ exports.getHubList = async(ctx) => {
69 } 69 }
70 70
71 ctx.status = 200; 71 ctx.status = 200;
72 - ctx.body = hubList; 72 + ctx.body = {
73 + hubList
74 + };
73 }; 75 };
74 76
75 exports.hubDisconnect = async(ctx) => { 77 exports.hubDisconnect = async(ctx) => {
......
...@@ -30,7 +30,9 @@ exports.getDoctorRegReqList = async ctx => { ...@@ -30,7 +30,9 @@ exports.getDoctorRegReqList = async ctx => {
30 }); 30 });
31 31
32 ctx.status = 200; 32 ctx.status = 200;
33 - ctx.body = doctorRegReqList; 33 + ctx.body = {
34 + doctorRegReqList
35 + };
34 36
35 } catch(e) { 37 } catch(e) {
36 ctx.status = 500; 38 ctx.status = 500;
...@@ -107,7 +109,9 @@ exports.getDoctorRegReqDetail = async ctx => { ...@@ -107,7 +109,9 @@ exports.getDoctorRegReqDetail = async ctx => {
107 } 109 }
108 110
109 ctx.status = 200; 111 ctx.status = 200;
110 - ctx.body = doctorInfo; 112 + ctx.body = {
113 + doctorInfo,
114 + };
111 115
112 } catch (e) { 116 } catch (e) {
113 ctx.status = 500; 117 ctx.status = 500;
......
...@@ -10,10 +10,12 @@ exports.medicineSearch = async(ctx) => { ...@@ -10,10 +10,12 @@ exports.medicineSearch = async(ctx) => {
10 10
11 const { keyword } = ctx.request.body; 11 const { keyword } = ctx.request.body;
12 12
13 - const result = await Medicine.findByKeyword(keyword); 13 + const medicineList = await Medicine.findByKeyword(keyword);
14 14
15 ctx.status = 200; 15 ctx.status = 200;
16 - ctx.body = result; 16 + ctx.body = {
17 + medicineList,
18 + };
17 } 19 }
18 20
19 exports.medicineGet = async(ctx) => { 21 exports.medicineGet = async(ctx) => {
...@@ -31,6 +33,8 @@ exports.medicineGet = async(ctx) => { ...@@ -31,6 +33,8 @@ exports.medicineGet = async(ctx) => {
31 } 33 }
32 34
33 ctx.status = 200; 35 ctx.status = 200;
34 - ctx.body = medicine; 36 + ctx.body = {
37 + medicine,
38 + };
35 39
36 } 40 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -29,7 +29,9 @@ exports.getMyDetail = async ctx => { ...@@ -29,7 +29,9 @@ exports.getMyDetail = async ctx => {
29 const profile = await Profile.findByUserId(userId); 29 const profile = await Profile.findByUserId(userId);
30 30
31 ctx.status = 200; 31 ctx.status = 200;
32 - ctx.body = profile; 32 + ctx.body = {
33 + profile,
34 + };
33 35
34 } 36 }
35 37
...@@ -78,7 +80,9 @@ exports.getMyDoctorList = async ctx => { ...@@ -78,7 +80,9 @@ exports.getMyDoctorList = async ctx => {
78 })); 80 }));
79 81
80 ctx.status = 200; 82 ctx.status = 200;
81 - ctx.body = doctorList; 83 + ctx.body = {
84 + doctorList,
85 + };
82 86
83 }; 87 };
84 88
...@@ -105,7 +109,9 @@ exports.viewAllDoctorRegisterReq = async ctx => { ...@@ -105,7 +109,9 @@ exports.viewAllDoctorRegisterReq = async ctx => {
105 const patientInfoList = await PatientInfo.findAllByPatientIdAndUseYn(userId, 'W'); 109 const patientInfoList = await PatientInfo.findAllByPatientIdAndUseYn(userId, 'W');
106 110
107 ctx.status = 200; 111 ctx.status = 200;
108 - ctx.body = patientInfoList; 112 + ctx.body = {
113 + patientInfoList,
114 + };
109 115
110 }; 116 };
111 117
......