박권수

Merge branch 'server' into web

...@@ -12,12 +12,20 @@ const user = new Router(); ...@@ -12,12 +12,20 @@ const user = new Router();
12 user.get('/', userCtrl.getMyDetail); 12 user.get('/', userCtrl.getMyDetail);
13 13
14 /** 14 /**
15 + * 현재 로그인한 유저에 등록된 의사 목록 가져옴
16 + * request parameter : token
17 + * url : http://localhost:4000/api/user/doctor
18 + * return : Doctor List
19 + */
20 +user.get('/doctor', userCtrl.getMyDoctorList);
21 +
22 +/**
15 * 유저를 등록하려는 의사의 요청을 전부 보여준다 23 * 유저를 등록하려는 의사의 요청을 전부 보여준다
16 * request parameter : token, 24 * request parameter : token,
17 * url : http://localhost:4000/api/user/doctorrequest 25 * url : http://localhost:4000/api/user/doctorrequest
18 * return : List 26 * return : List
19 */ 27 */
20 -user.get('/doctorrequest', userCtrl.viewAllDoctorRegister); 28 +user.get('/doctorrequest', userCtrl.viewAllDoctorRegisterReq);
21 29
22 30
23 /** 31 /**
...@@ -30,3 +38,4 @@ user.post('/doctorrequest', userCtrl.acceptDoctorRegister); ...@@ -30,3 +38,4 @@ user.post('/doctorrequest', userCtrl.acceptDoctorRegister);
30 38
31 39
32 module.exports = user; 40 module.exports = user;
41 +
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
2 const User = require('../../models/user'); 2 const User = require('../../models/user');
3 const Profile = require('../../models/profile'); 3 const Profile = require('../../models/profile');
4 const PatientInfo = require('../../models/patientInfo'); 4 const PatientInfo = require('../../models/patientInfo');
5 +const DoctorInfo = require('../../models/doctorInfo');
5 const jwt = require('jsonwebtoken'); 6 const jwt = require('jsonwebtoken');
6 7
7 8
...@@ -41,11 +42,50 @@ exports.updateMyInfo = async ctx => { ...@@ -41,11 +42,50 @@ exports.updateMyInfo = async ctx => {
41 }; 42 };
42 43
43 /** 44 /**
45 + * 현재 로그인한 유저(환자)를 관리하는 의사 목록을 가져온다.
46 + * http methods : get
47 + * @param {*} ctx
48 + * @returns
49 + */
50 +exports.getMyDoctorList = async ctx => {
51 + const token = ctx.req.headers.authorization
52 + if (!token || !token.length) {
53 + ctx.status = 401
54 + return
55 + }
56 +
57 + const { userId } = jwt.verify(token, process.env.JWT_SECRET)
58 + const user = await User.findByUserId(userId)
59 + if(!user || user.userTypeCd !== 'NORMAL' || user.useYn !== 'Y') {
60 + ctx.status = 403;
61 + return;
62 + }
63 +
64 + const patientInfoList = await PatientInfo.find({
65 + patientId : userId,
66 + useYn : 'Y',
67 + });
68 +
69 + const doctorList = await Promise.all(patientInfoList.map(async patientInfo => {
70 + const doctorInfo = await DoctorInfo.findOne({
71 + doctorId : patientInfo.doctorId,
72 + useYn : 'Y',
73 + });
74 +
75 + return doctorInfo.info;
76 + }));
77 +
78 + ctx.status = 200;
79 + ctx.body = doctorList;
80 +
81 +};
82 +
83 +/**
44 * 의사가 요청한 환자 등록을 확인한다. 84 * 의사가 요청한 환자 등록을 확인한다.
45 * @param {*} ctx 85 * @param {*} ctx
46 * http methods : get 86 * http methods : get
47 */ 87 */
48 -exports.viewAllDoctorRegister = async ctx => { 88 +exports.viewAllDoctorRegisterReq = async ctx => {
49 const token = ctx.req.headers.authorization 89 const token = ctx.req.headers.authorization
50 if (!token || !token.length) { 90 if (!token || !token.length) {
51 ctx.status = 401 91 ctx.status = 401
...@@ -99,3 +139,4 @@ exports.acceptDoctorRegister = async ctx => { ...@@ -99,3 +139,4 @@ exports.acceptDoctorRegister = async ctx => {
99 ctx.status = 200; 139 ctx.status = 200;
100 140
101 }; 141 };
142 +
......
...@@ -9,6 +9,8 @@ const DoctorInfoSchema = new Schema({ ...@@ -9,6 +9,8 @@ const DoctorInfoSchema = new Schema({
9 hospitalNm : { type : String, default : null, }, 9 hospitalNm : { type : String, default : null, },
10 hospitalAddr : { type : String, default : null, }, 10 hospitalAddr : { type : String, default : null, },
11 contact : { type : String, required : true, }, 11 contact : { type : String, required : true, },
12 + doctorType : { type : String, default : null, },
13 + doctorNm : { type : String, required : true, },
12 }, 14 },
13 useYn : { type : String, default : 'W', required : true, }, 15 useYn : { type : String, default : 'W', required : true, },
14 }); 16 });
...@@ -22,4 +24,4 @@ DoctorInfoSchema.methods.setUseYn = function(useYn) { ...@@ -22,4 +24,4 @@ DoctorInfoSchema.methods.setUseYn = function(useYn) {
22 }; 24 };
23 25
24 26
25 -module.exports = mongoose.model('DoctorInfo', DoctorInfoSchema);
...\ No newline at end of file ...\ No newline at end of file
27 +module.exports = mongoose.model('DoctorInfo', DoctorInfoSchema);
......