박권수

feat. create Model : [DoctorInfo, PatientInfo, Feedback, Profile], doctor Api, u…

…pdate User Api, update Doctor Register, update Model : [User, Bottle]
1 { 1 {
2 "extends": "eslint:recommended", 2 "extends": "eslint:recommended",
3 "rules": { 3 "rules": {
4 - "semi": ["warn", "never"], 4 + // "semi": ["warn", "never"],
5 "quotes": ["warn", "single"], 5 "quotes": ["warn", "single"],
6 - "no-console": ["off"] 6 + "no-console": ["off"],
7 + "no-unused-vars": ["warn", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }],
8 + "no-constant-condition" : ["off"]
7 }, 9 },
8 "parserOptions": { 10 "parserOptions": {
9 "ecmaVersion": 9 11 "ecmaVersion": 9
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 "author": "박권수", 17 "author": "박권수",
18 "license": "ISC", 18 "license": "ISC",
19 "dependencies": { 19 "dependencies": {
20 + "moment": "^2.29.1",
20 "mqtt": "^4.2.6" 21 "mqtt": "^4.2.6"
21 } 22 }
22 } 23 }
......
1 //회원가입, 로그인 및 로그아웃에 관한 api 1 //회원가입, 로그인 및 로그아웃에 관한 api
2 const User = require('../../models/user'); 2 const User = require('../../models/user');
3 +const Profile = require('../../models/profile');
4 +const DoctorInfo = require('../../models/doctorInfo');
3 const Joi = require('joi'); 5 const Joi = require('joi');
6 +const jwt = require('jsonwebtoken');
4 7
5 8
6 exports.register = async(ctx) => { 9 exports.register = async(ctx) => {
7 - const { userId, password, passwordCheck } = ctx.request.body; 10 + const {
11 + userId,
12 + password,
13 + passwordCheck,
14 + userNm,
15 + userAge,
16 + contact,
17 + } = ctx.request.body;
8 18
9 const schema = Joi.object().keys({ 19 const schema = Joi.object().keys({
10 userId : Joi.string().email().max(50).required(), 20 userId : Joi.string().email().max(50).required(),
...@@ -25,16 +35,75 @@ exports.register = async(ctx) => { ...@@ -25,16 +35,75 @@ exports.register = async(ctx) => {
25 } 35 }
26 36
27 const user = new User({ 37 const user = new User({
28 - userId 38 + userId,
39 + userTypeCd : 'NORMAL',
40 + useYn : 'Y',
29 }); 41 });
30 42
31 await user.setPassword(password); 43 await user.setPassword(password);
32 await user.save(); 44 await user.save();
33 45
46 + const profile = new Profile({
47 + userId,
48 + userNm,
49 + userAge,
50 + contact,
51 + });
52 +
53 + await profile.save();
54 +
34 ctx.status = 201; 55 ctx.status = 201;
35 56
36 }; 57 };
37 58
59 +exports.doctorRegister = async ctx => {
60 + const {
61 + userId,
62 + password,
63 + passwordCheck,
64 + info,
65 + } = ctx.request.body;
66 +
67 + const schema = Joi.object().keys({
68 + userId : Joi.string().email().max(50).required(),
69 + password : Joi.string().required(),
70 + passwordCheck : Joi.string().required(),
71 + })
72 +
73 + const result = schema.validate(ctx.request.body);
74 + if(result.error || password !== passwordCheck) {
75 + ctx.status = 400;
76 + return;
77 + }
78 +
79 + const existUser = await User.findByUserId(userId);
80 + const existDoctorInfo = await DoctorInfo.findByDoctorId(userId);
81 + if(existUser || existDoctorInfo) {
82 + ctx.status = 409;
83 + return;
84 + }
85 +
86 + const doctor = new User({
87 + userId,
88 + userTypeCd : 'DOCTOR',
89 + useYn : 'W',
90 + });
91 +
92 + await doctor.setPassword(password);
93 + doctor.save();
94 +
95 + const doctorInfo = new DoctorInfo({
96 + doctorId : userId,
97 + info,
98 + useYn : 'W',
99 + });
100 +
101 + doctorInfo.save();
102 +
103 + ctx.status = 201;
104 +
105 +}
106 +
38 exports.login = async(ctx) => { 107 exports.login = async(ctx) => {
39 const { userId, password } = ctx.request.body; 108 const { userId, password } = ctx.request.body;
40 109
...@@ -61,6 +130,11 @@ exports.login = async(ctx) => { ...@@ -61,6 +130,11 @@ exports.login = async(ctx) => {
61 return; 130 return;
62 } 131 }
63 132
133 + if(user.useYn !== 'Y') {
134 + ctx.status = 403;
135 + return;
136 + }
137 +
64 const token = await user.generateToken(); 138 const token = await user.generateToken();
65 ctx.cookies.set('access_token', token, { 139 ctx.cookies.set('access_token', token, {
66 httpOnly : true, 140 httpOnly : true,
...@@ -82,4 +156,32 @@ exports.logout = async(ctx) => { ...@@ -82,4 +156,32 @@ exports.logout = async(ctx) => {
82 }); 156 });
83 157
84 ctx.status = 204; 158 ctx.status = 204;
159 +};
160 +
161 +exports.verifyToken = async(ctx) => {
162 + const token = ctx.req.headers.authorization;
163 + if(!token || !token.length) {
164 + ctx.status = 400;
165 + ctx.body = {
166 + name : 'Token Not Exist',
167 + message : 'Not Exist Token',
168 + expiredAt : null,
169 + };
170 + return;
171 + }
172 +
173 + await jwt.verify(token, process.env.JWT_SECRET, (err, decoded) => {
174 + if(err) {
175 + ctx.status = 400;
176 + ctx.body = err;
177 + return;
178 + }
179 + });
180 +
181 + ctx.status = 200;
182 + ctx.body = {
183 + name : 'Token Exist',
184 + message : 'Token Work',
185 + expiredAt : null,
186 + };
85 }; 187 };
...\ No newline at end of file ...\ No newline at end of file
......
1 -const Router = require('koa-router'); 1 +const Router = require('koa-router')
2 -const authCtrl = require('./auth.ctrl'); 2 +const authCtrl = require('./auth.ctrl')
3 3
4 -const auth = new Router(); 4 +const auth = new Router()
5 5
6 /** 6 /**
7 - * 회원가입 (email type) 7 + * 회원가입 (email type) : 환자 회원가입
8 * url : http://localhost:4000/api/auth/register 8 * url : http://localhost:4000/api/auth/register
9 * request parameter : userId, password, passwordCheck 9 * request parameter : userId, password, passwordCheck
10 * return : null 10 * return : null
11 */ 11 */
12 -auth.post('/register', authCtrl.register); 12 +auth.post('/register', authCtrl.register)
13 +
14 +/**
15 + * 회원가입 (email type) : 의사 회원가입
16 + * url : http://localhost:4000/api/auth/register/doctor
17 + * request parameter : userId, password, passwordCheck, doctorInfo
18 + * return : null
19 + */
20 + auth.post('/register/doctor', authCtrl.doctorRegister)
13 21
14 /** 22 /**
15 * 로그인 (email type) 23 * 로그인 (email type)
...@@ -17,7 +25,7 @@ auth.post('/register', authCtrl.register); ...@@ -17,7 +25,7 @@ auth.post('/register', authCtrl.register);
17 * request parameter : userId, password 25 * request parameter : userId, password
18 * return : userId 26 * return : userId
19 */ 27 */
20 -auth.post('/login', authCtrl.login); 28 +auth.post('/login', authCtrl.login)
21 29
22 /** 30 /**
23 * 로그아웃 31 * 로그아웃
...@@ -25,6 +33,14 @@ auth.post('/login', authCtrl.login); ...@@ -25,6 +33,14 @@ auth.post('/login', authCtrl.login);
25 * request parameter : null 33 * request parameter : null
26 * return : null 34 * return : null
27 */ 35 */
28 -auth.post('/logout', authCtrl.logout); 36 +auth.post('/logout', authCtrl.logout)
37 +
38 +/**
39 + * 토큰이 유효한지 확인
40 + * url : http://localhost:4000/api/auth/verifytoken
41 + * request parameter : token(headers : authorization)
42 + * return : result;
43 + */
44 +auth.get('/verifytoken', authCtrl.verifyToken);
29 45
30 module.exports = auth; 46 module.exports = auth;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -3,6 +3,7 @@ const Bottle = require('../../models/bottle'); ...@@ -3,6 +3,7 @@ const Bottle = require('../../models/bottle');
3 const Hub = require('../../models/hub'); 3 const Hub = require('../../models/hub');
4 const Medicine = require('../../models/medicine'); 4 const Medicine = require('../../models/medicine');
5 const User = require('../../models/user'); 5 const User = require('../../models/user');
6 +const History = require('../../models/history');
6 const Mqtt = require('../../lib/MqttModule'); 7 const Mqtt = require('../../lib/MqttModule');
7 const jwt = require('jsonwebtoken'); 8 const jwt = require('jsonwebtoken');
8 9
...@@ -16,7 +17,7 @@ exports.bottleConnect = async(ctx) => { ...@@ -16,7 +17,7 @@ exports.bottleConnect = async(ctx) => {
16 17
17 const { userId } = jwt.verify(token, process.env.JWT_SECRET); 18 const { userId } = jwt.verify(token, process.env.JWT_SECRET);
18 const user = await User.findById(userId); 19 const user = await User.findById(userId);
19 - if(!user || !user.userTypeCd) { 20 + if(!user || !user.userTypeCd || user.useYn !== 'Y') {
20 ctx.status = 403; 21 ctx.status = 403;
21 return; 22 return;
22 } 23 }
...@@ -70,7 +71,7 @@ exports.bottleDisconnect = async(ctx) => { ...@@ -70,7 +71,7 @@ exports.bottleDisconnect = async(ctx) => {
70 71
71 const { userId } = jwt.verify(token, process.env.JWT_SECRET); 72 const { userId } = jwt.verify(token, process.env.JWT_SECRET);
72 const user = await User.findById(userId); 73 const user = await User.findById(userId);
73 - if(!user || !user.userTypeCd) { 74 + if(!user || !user.userTypeCd || user.useYn !== 'Y') {
74 ctx.status = 403; 75 ctx.status = 403;
75 return; 76 return;
76 } 77 }
...@@ -102,7 +103,7 @@ exports.bottleDisconnect = async(ctx) => { ...@@ -102,7 +103,7 @@ exports.bottleDisconnect = async(ctx) => {
102 }; 103 };
103 104
104 //약병 정보를 조회 -> 약병에 현재 데이터를 요청한다. message : req 105 //약병 정보를 조회 -> 약병에 현재 데이터를 요청한다. message : req
105 -exports.lookupInfo = async(ctx) => { 106 +exports.getBottleInfo = async(ctx) => {
106 const token = ctx.req.headers.authorization; 107 const token = ctx.req.headers.authorization;
107 if(!token || !token.length) { 108 if(!token || !token.length) {
108 ctx.status = 401; 109 ctx.status = 401;
...@@ -111,36 +112,52 @@ exports.lookupInfo = async(ctx) => { ...@@ -111,36 +112,52 @@ exports.lookupInfo = async(ctx) => {
111 112
112 const { userId } = jwt.verify(token, process.env.JWT_SECRET); 113 const { userId } = jwt.verify(token, process.env.JWT_SECRET);
113 const user = await User.findById(userId); 114 const user = await User.findById(userId);
114 - if(!user || !user.userTypeCd) { 115 + if(!user || !user.userTypeCd || user.useYn !== 'Y') {
115 ctx.status = 403; 116 ctx.status = 403;
116 return; 117 return;
117 } 118 }
118 119
119 const { bottleId } = ctx.params; 120 const { bottleId } = ctx.params;
120 121
121 - const isBottleExist = await Bottle.findByBottleId(bottleId); 122 + const bottle = await Bottle.findByBottleId(bottleId);
122 - if(!isBottleExist) { 123 + if(!bottle) {
123 ctx.status = 404; 124 ctx.status = 404;
124 return; 125 return;
125 } 126 }
126 127
127 - const hub = await Hub.findByHubId(isBottleExist.getHubId()); 128 + const hub = await Hub.findByHubId(bottle.getHubId());
128 - if(hub.getHub_UserId() !== userId) { 129 + if(hub.getHub_UserId() !== userId || user.userTypeCd !== 'DOCTOR') {
129 ctx.status = 403; 130 ctx.status = 403;
130 return; 131 return;
131 } 132 }
132 133
133 - const hosting = hub.getHubHost(); 134 + if(user.userTypeCd === 'NORMAL') {
134 - //서버에서 bottle로 데이터를 요청한다. 135 + const hosting = hub.getHubHost();
135 - const client = await Mqtt.mqttOn(hosting); 136 + //서버에서 bottle로 데이터를 요청한다.
136 - const topic = 'bottle/' + bottleId + '/stb'; 137 + const client = await Mqtt.mqttOn(hosting);
137 - const message = 'req'; 138 + const topic = 'bottle/' + bottleId + '/stb';
138 - await Mqtt.mqttPublishMessage(client, { topic, message }); 139 + const message = 'req';
140 + await Mqtt.mqttPublishMessage(client, { topic, message });
139 141
140 - const bottle = await Bottle.findByBottleId(bottleId); 142 + const bottle = await Bottle.findByBottleId(bottleId);
141 - 143 +
142 - ctx.status = 200; 144 + ctx.status = 200;
143 - ctx.body = bottle; 145 + ctx.body = bottle;
146 +
147 + return;
148 + } else if (user.userTypeCd === 'DOCTOR') {
149 + let result = {
150 + bottle,
151 + history : [],
152 + };
153 +
154 + result.historyList = History.findByBottleId(bottle.bottleId);
155 +
156 + ctx.status = 200;
157 + ctx.body = result;
158 +
159 + return;
160 + }
144 } 161 }
145 162
146 //약병의 ID를 찾아서 약의 정보를 등록 : Post 163 //약병의 ID를 찾아서 약의 정보를 등록 : Post
...@@ -153,7 +170,7 @@ exports.setMedicine = async(ctx) => { ...@@ -153,7 +170,7 @@ exports.setMedicine = async(ctx) => {
153 170
154 const { userId } = jwt.verify(token, process.env.JWT_SECRET); 171 const { userId } = jwt.verify(token, process.env.JWT_SECRET);
155 const user = await User.findById(userId); 172 const user = await User.findById(userId);
156 - if(!user || !user.userTypeCd) { 173 + if(!user || !user.userTypeCd || user.useYn !== 'Y') {
157 ctx.status = 403; 174 ctx.status = 403;
158 return; 175 return;
159 } 176 }
...@@ -199,7 +216,7 @@ exports.getBottleList = async(ctx) => { ...@@ -199,7 +216,7 @@ exports.getBottleList = async(ctx) => {
199 216
200 const { userId } = jwt.verify(token, process.env.JWT_SECRET); 217 const { userId } = jwt.verify(token, process.env.JWT_SECRET);
201 const user = await User.findById(userId); 218 const user = await User.findById(userId);
202 - if(!user || !user.userTypeCd) { 219 + if(!user || !user.userTypeCd || user.useYn !== 'Y') {
203 ctx.status = 403; 220 ctx.status = 403;
204 return; 221 return;
205 } 222 }
......
...@@ -25,7 +25,7 @@ bottle.delete('/:bottleId', bottleCtrl.bottleDisconnect); ...@@ -25,7 +25,7 @@ bottle.delete('/:bottleId', bottleCtrl.bottleDisconnect);
25 * url : http://localhost:4000/api/bottle/:bottleId 25 * url : http://localhost:4000/api/bottle/:bottleId
26 * return : bottle(json type) 26 * return : bottle(json type)
27 */ 27 */
28 -bottle.get('/:bottleId', bottleCtrl.lookupInfo); 28 +bottle.get('/:bottleId', bottleCtrl.getBottleInfo);
29 29
30 /** 30 /**
31 * 약병에 약 등록 = 약 검색 후 약 ID(medicineId)와 복용 정보 보고 사용자가 약 복용량(dosage) 입력 31 * 약병에 약 등록 = 약 검색 후 약 ID(medicineId)와 복용 정보 보고 사용자가 약 복용량(dosage) 입력
......
1 +//의사가 사용할 수 있는 Api
2 +const User = require('../../models/user');
3 +const Profile = require('../../models/profile');
4 +const Bottle = require('../../models/bottle');
5 +const Medicine = require('../../models/medicine');
6 +const History = require('../../models/history');
7 +const Feedback = require('../../models/feedback');
8 +const Hub = require('../../models/hub');
9 +const PatientInfo = require('../../models/patientInfo');
10 +const jwt = require('jsonwebtoken');
11 +
12 +/**
13 + * 관리하는 환자 목록을 모두 가져옴
14 + * @param {*} ctx
15 + * http methods : GET
16 + */
17 +exports.getPatientList = async ctx => {
18 + const token = ctx.req.headers.authorization;
19 + if (!token || !token.length) {
20 + ctx.status = 401;
21 + return;
22 + }
23 +
24 + const { userId } = jwt.verify(token, process.env.JWT_SECRET);
25 + const user = await User.findById(userId);
26 + if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') {
27 + ctx.status = 403;
28 + return;
29 + }
30 +
31 + const managePatientIdList = await PatientInfo.findAllByDoctorId(userId);
32 +
33 + const result = managePatientIdList.map(async patientId => {
34 + const patient = await User.findByUserId(patientId);
35 + return patient;
36 + });
37 +
38 + ctx.status = 200;
39 + ctx.body = result;
40 +
41 +};
42 +
43 +/**
44 + * 관리하는 특정 환자의 정보를 가져온다.
45 + * @param {*} ctx
46 + * http methods : GET
47 + */
48 +exports.getPatientDetail = async ctx => {
49 + const token = ctx.req.headers.authorization;
50 + if (!token || !token.length) {
51 + ctx.status = 401;
52 + return;
53 + }
54 +
55 + const { userId } = jwt.verify(token, process.env.JWT_SECRET);
56 + const user = await User.findById(userId);
57 + if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') {
58 + ctx.status = 403;
59 + return;
60 + }
61 +
62 + const { patientId } = ctx.params;
63 + const patient = await User.findByUserId(patientId);
64 + if(!patient || patient.useYn !== 'Y') {
65 + ctx.status = 404;
66 + return;
67 + }
68 +
69 + const isDoctorsPatient = await PatientInfo.findByPatientIdAndDoctorId(patientId, userId);
70 + if(!isDoctorsPatient) {
71 + ctx.status = 403;
72 + return;
73 + }
74 +
75 + const profile = await Profile.findByUserId(patientId);
76 +
77 + //reqUser의 약병 조회도 한번에
78 + const reqUserHubList = await Hub.findAllByUserId(patientId);
79 + const reqUserBottleList = [];
80 + await Promise.all(reqUserHubList.map(async hub => {
81 + const bottleList = await Bottle.findAllByHubId(hub.hubId);
82 + reqUserBottleList.push(...bottleList);
83 + }));
84 +
85 + const result = {
86 + ...profile,
87 + info : isDoctorsPatient.getInfo(),
88 + bottleList : reqUserBottleList,
89 + };
90 +
91 + ctx.status = 200;
92 + ctx.body = result;
93 +
94 +};
95 +
96 +/**
97 + * 관리하는 환자의 특병 약병을 조회하여, 복용을 잘 하고 있는지 확인한다.
98 + * @param {*} ctx
99 + * http methods : GET
100 + */
101 +exports.getBottleDetail = async ctx => {
102 + const token = ctx.req.headers.authorization;
103 + if (!token || !token.length) {
104 + ctx.status = 401;
105 + return;
106 + }
107 +
108 + const { userId } = jwt.verify(token, process.env.JWT_SECRET);
109 + const user = await User.findById(userId);
110 + if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') {
111 + ctx.status = 403;
112 + return;
113 + }
114 +
115 + const { bottleId } = ctx.params;
116 + const bottle = await Bottle.findByBottleId(bottleId);
117 + if(!bottle) {
118 + ctx.status = 404;
119 + return;
120 + }
121 + if(bottle.getDoctorId() !== userId) {
122 + ctx.status = 403;
123 + return;
124 + }
125 +
126 +
127 + //약병에 들어있는 약 정보와 복용 내역을 가져온다.
128 + const bottleInfo = {
129 + temperature : bottle.temperature,
130 + humidity : bottle.humidity,
131 + dosage : bottle.dosage,
132 + balance : bottle.balance,
133 + };
134 +
135 + const medicine = await Medicine.findByMedicineId(bottle.getMedicineId());
136 + const takeHistory = await History.findByBottleIdAndMedicineId(bottleId, bottle.getMedicineId());
137 +
138 + const result = {
139 + bottleInfo,
140 + medicine,
141 + takeHistory,
142 + };
143 +
144 + ctx.status = 200;
145 + ctx.body = result;
146 +
147 +};
148 +
149 +/**
150 + * 특정 환자의 특이사항을 기록한다.
151 + * @param {*} ctx
152 + * http methods : PATCH
153 + */
154 +exports.writeReqPatientReport = async ctx => {
155 + const token = ctx.req.headers.authorization;
156 + if (!token || !token.length) {
157 + ctx.status = 401;
158 + return;
159 + }
160 +
161 + const { userId } = jwt.verify(token, process.env.JWT_SECRET);
162 + const user = await User.findById(userId);
163 + if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') {
164 + ctx.status = 403;
165 + return;
166 + }
167 +
168 + const { reqUserId, info } = ctx.request.body;
169 + const patient = await User.findByUserId(reqUserId);
170 + if(!patient || patient.useYn !== 'Y') {
171 + ctx.status = 404;
172 + return;
173 + }
174 +
175 + const patientInfo = await PatientInfo.findByPatientIdAndDoctorId(reqUserId, userId);
176 + if(!patientInfo) {
177 + ctx.status = 404;
178 + return;
179 + }
180 +
181 + await patientInfo.updateInfo(info);
182 + patientInfo.save();
183 +
184 + ctx.status = 200;
185 +
186 +};
187 +
188 +/**
189 + * 약을 복용중인 환자의 약병(=복용중인 약)에 대한 피드백을 등록한다.
190 + * @param {*} ctx
191 + * http methods : POST
192 + */
193 +exports.writeReqBottleFeedback = async ctx => {
194 + const token = ctx.req.headers.authorization;
195 + if (!token || !token.length) {
196 + ctx.status = 401;
197 + return;
198 + }
199 +
200 + const { userId } = jwt.verify(token, process.env.JWT_SECRET);
201 + const user = await User.findById(userId);
202 + if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') {
203 + ctx.status = 403;
204 + return;
205 + }
206 +
207 + const { bottleId, fdbType, feedback } = ctx.request.body;
208 + const bottle = await Bottle.findByBottleId(bottleId);
209 + if(!bottle) {
210 + ctx.status = 404;
211 + return;
212 + }
213 + if(bottle.getDoctorId() !== userId) {
214 + ctx.status = 403;
215 + return;
216 + }
217 +
218 + const newFeedback = new Feedback({
219 + fdbDtm : new Date(),
220 + fdbType,
221 + bottleId,
222 + doctorId : userId,
223 + feedback,
224 + });
225 + newFeedback.save();
226 +
227 + ctx.status = 200;
228 +
229 +};
230 +
231 +/**
232 + * 새로운 환자를 등록한다.
233 + * @param {*} ctx
234 + * http methods : POST
235 + */
236 +exports.registerNewPatient = async ctx => {
237 + const token = ctx.req.headers.authorization;
238 + if (!token || !token.length) {
239 + ctx.status = 401;
240 + return;
241 + }
242 +
243 + const { userId } = jwt.verify(token, process.env.JWT_SECRET);
244 + const user = await User.findById(userId);
245 + if(!user || user.userTypeCd !== 'DOCTOR') {
246 + ctx.status = 403;
247 + return;
248 + }
249 +
250 + const { reqUserId } = ctx.request.body;
251 + const patient = await User.findByUserId(reqUserId);
252 + if(!patient || patient.useYn !== 'Y') {
253 + ctx.status = 404;
254 + return;
255 + }
256 +
257 + const patientInfo = new PatientInfo({
258 + patientId : reqUserId,
259 + doctorId : userId,
260 + info : '',
261 + });
262 +
263 + patientInfo.updateInfo('환자 등록');
264 + patientInfo.save();
265 +
266 + ctx.status = 200;
267 +
268 +};
269 +
270 +/**
271 + * 등록된 환자를 해제한다.
272 + * @param {*} ctx
273 + * http methods : DELETE
274 + */
275 +exports.removeReqPatient = async ctx => {
276 + const token = ctx.req.headers.authorization;
277 + if (!token || !token.length) {
278 + ctx.status = 401;
279 + return;
280 + }
281 +
282 + const { userId } = jwt.verify(token, process.env.JWT_SECRET);
283 + const user = await User.findById(userId);
284 + if(!user || user.userTypeCd !== 'DOCTOR') {
285 + ctx.status = 403;
286 + return;
287 + }
288 +
289 + const { patientId } = ctx.params;
290 + const patient = await User.findByUserId(patientId);
291 + if(!patient || patient.useYn !== 'Y') {
292 + ctx.status = 404;
293 + return;
294 + }
295 +
296 + const patientInfo = await PatientInfo.findByPatientIdAndDoctorId(patientId, userId);
297 + if(!patientInfo) {
298 + ctx.status = 404;
299 + return;
300 + }
301 +
302 + await PatientInfo.deleteOne({
303 + patientId,
304 + doctorId : userId,
305 + });
306 +
307 + ctx.status = 200;
308 +
309 +};
...\ No newline at end of file ...\ No newline at end of file
1 +const Router = require('koa-router');
2 +const doctorCtrl = require('./doctor.ctrl');
3 +
4 +const doctor = new Router();
5 +
6 +/**
7 + * 현재 로그인한 유저(의사)의 관리 환자 목록을 가져옴
8 + * request parameter
9 + * url : http://localhost:4000/doctor/patient
10 + * return : patient List
11 + */
12 +doctor.get('/patient', doctorCtrl.getPatientList);
13 +
14 +/**
15 + * 현재 로그인한 유저(의사)의 관리 환자 상세 정보를 가져옴
16 + * request parameter : patient Id
17 + * url : http://localhost:4000/doctor/patient/:patientId
18 + * return : patient Detail
19 + */
20 +doctor.get('/patient/:patientId', doctorCtrl.getPatientDetail);
21 +
22 +/**
23 + * 현재 로그인한 유저(의사)의 관리 약병 상세 정보를 가져옴
24 + * request parameter : bottle Id
25 + * url : http://localhost:4000/doctor/bottle/:bottleId
26 + * return : bottle Detail
27 + */
28 +doctor.get('/bottle/:bottleId', doctorCtrl.getBottleDetail);
29 +
30 +
31 +/**
32 + * 현재 로그인한 유저(의사)의 특정 관리 환자의 특이사항을 기록함
33 + * request parameter : reqUserId, info
34 + * url : http://localhost:4000/doctor/patient
35 + * return : null
36 + */
37 +doctor.patch('/patient', doctorCtrl.writeReqPatientReport);
38 +
39 +/**
40 + * 현재 로그인한 유저(의사)의 특정 관리 환자의 약병의 피드백을 기록함
41 + * request parameter : bottleId, fdbType, feedback
42 + * url : http://localhost:4000/doctor/bottle
43 + * return : null
44 + */
45 +doctor.post('/bottle', doctorCtrl.writeReqBottleFeedback);
46 +
47 +/**
48 + * 현재 로그인한 유저(의사)의 관리 환자를 등록함.
49 + * request parameter : reqUserId
50 + * url : http://localhost:4000/doctor/patient
51 + * return : null
52 + */
53 +doctor.post('/patient', doctorCtrl.registerNewPatient);
54 +
55 +/**
56 + * 현재 로그인한 유저(의사)의 특정 관리 환자를 삭제함.
57 + * request parameter : patientId
58 + * url : http://localhost:4000/doctor/patient/:patientId
59 + * return : null
60 + */
61 +doctor.delete('/patient/:patientId', doctorCtrl.removeReqPatient);
62 +
63 +
64 +module.exports = doctor;
65 +
...\ No newline at end of file ...\ No newline at end of file
...@@ -14,7 +14,7 @@ exports.hubConnect = async (ctx) => { ...@@ -14,7 +14,7 @@ exports.hubConnect = async (ctx) => {
14 14
15 const { userId } = jwt.verify(token, process.env.JWT_SECRET); 15 const { userId } = jwt.verify(token, process.env.JWT_SECRET);
16 const user = await User.findById(userId); 16 const user = await User.findById(userId);
17 - if(!user || !user.userTypeCd) { 17 + if(!user || !user.userTypeCd || user.useYn !== 'Y') {
18 ctx.status = 403; 18 ctx.status = 403;
19 return; 19 return;
20 } 20 }
...@@ -55,7 +55,7 @@ exports.getHubList = async(ctx) => { ...@@ -55,7 +55,7 @@ exports.getHubList = async(ctx) => {
55 55
56 const { userId } = jwt.verify(token, process.env.JWT_SECRET); 56 const { userId } = jwt.verify(token, process.env.JWT_SECRET);
57 const user = await User.findById(userId); 57 const user = await User.findById(userId);
58 - if(!user || !user.userTypeCd) { 58 + if(!user || !user.userTypeCd || user.useYn !== 'Y') {
59 ctx.status = 403; 59 ctx.status = 403;
60 return; 60 return;
61 } 61 }
...@@ -79,7 +79,7 @@ exports.hubDisconnect = async(ctx) => { ...@@ -79,7 +79,7 @@ exports.hubDisconnect = async(ctx) => {
79 79
80 const { userId } = jwt.verify(token, process.env.JWT_SECRET); 80 const { userId } = jwt.verify(token, process.env.JWT_SECRET);
81 const user = await User.findById(userId); 81 const user = await User.findById(userId);
82 - if(!user || !user.userTypeCd) { 82 + if(!user || !user.userTypeCd || user.useYn !== 'Y') {
83 ctx.status = 403; 83 ctx.status = 403;
84 return; 84 return;
85 } 85 }
......
...@@ -4,13 +4,15 @@ const user = require('./user') ...@@ -4,13 +4,15 @@ const user = require('./user')
4 const bottle = require('./bottle') 4 const bottle = require('./bottle')
5 const hub = require('./hub') 5 const hub = require('./hub')
6 const medicine = require('./medicine') 6 const medicine = require('./medicine')
7 +const doctor = require('./doctor');
7 8
8 -const api = new Router() 9 +const api = new Router();
9 10
10 api.use('/auth', auth.routes()) 11 api.use('/auth', auth.routes())
11 -api.user('/user', user.routes()) 12 +api.use('/user', user.routes())
12 api.use('/bottle', bottle.routes()) 13 api.use('/bottle', bottle.routes())
13 api.use('/hub', hub.routes()) 14 api.use('/hub', hub.routes())
14 api.use('/medicine', medicine.routes()) 15 api.use('/medicine', medicine.routes())
16 +api.use('/doctor', doctor.routes());
15 17
16 -module.exports = api
...\ No newline at end of file ...\ No newline at end of file
18 +module.exports = api;
...\ No newline at end of file ...\ No newline at end of file
......
1 const Router = require('koa-router') 1 const Router = require('koa-router')
2 const userCtrl = require('./user.ctrl') 2 const userCtrl = require('./user.ctrl')
3 3
4 -const user = new Router() 4 +const user = new Router();
5 5
6 /** 6 /**
7 * 현재 유저 정보 조회 7 * 현재 유저 정보 조회
...@@ -9,21 +9,6 @@ const user = new Router() ...@@ -9,21 +9,6 @@ const user = new Router()
9 * url : http://localhost:4000/api/user 9 * url : http://localhost:4000/api/user
10 * return : Object User 10 * return : Object User
11 */ 11 */
12 -user.get('/', userCtrl.myInfo) 12 +user.get('/', userCtrl.getMyDetail);
13 -
14 -/**
15 - * 현재 유저의 타입에 따라 요청 유저 정보 조회(의사 : 환자, 관리자 : 모든 유저)
16 - * request parameter : token
17 - * url : http://localhost:4000/api/user/:reqUserId
18 - * return : status
19 - */
20 - user.get('/:reqUserId', userCtrl.getUserDetail)
21 -
22 - /**
23 - * 현재 유저의 타입에 따라 요청 유저 정보 수정(의사 : 환자, 관리자 : 모든 유저)
24 - * request parameter : token
25 - * url : http://localhost:4000/api/user/:reqUserId
26 - * return : status
27 - */
28 -user.patch('/:reqUserId', userCtrl.updateReqUser)
29 13
14 +module.exports = user;
......
1 //유저에 관련된 Api 1 //유저에 관련된 Api
2 -const User = require('../../models/user') 2 +const User = require('../../models/user');
3 -const Bottle = require('../../models/bottle') 3 +const Profile = require('../../models/profile');
4 -const Hub = require('../../models/hub') 4 +const jwt = require('jsonwebtoken');
5 -const jwt = require('jsonwebtoken')
6 5
7 6
8 -exports.myInfo = async ctx => { 7 +exports.getMyDetail = async ctx => {
9 const token = ctx.req.headers.authorization 8 const token = ctx.req.headers.authorization
10 if (!token || !token.length) { 9 if (!token || !token.length) {
11 ctx.status = 401 10 ctx.status = 401
...@@ -14,118 +13,19 @@ exports.myInfo = async ctx => { ...@@ -14,118 +13,19 @@ exports.myInfo = async ctx => {
14 13
15 const { userId } = jwt.verify(token, process.env.JWT_SECRET) 14 const { userId } = jwt.verify(token, process.env.JWT_SECRET)
16 const user = await User.findById(userId) 15 const user = await User.findById(userId)
17 - if(!user || !user.userTypeCd) { 16 + if(!user || !user.userTypeCd || user.useYn !== 'Y') {
18 - ctx.status = 403 17 + ctx.status = 403;
19 - return 18 + return;
20 - }
21 -
22 - let result = {
23 - myInfo : user,
24 - myDoctor : null,
25 - patientList : [],
26 - userList : [],
27 } 19 }
28 20
29 - if (user.userTypeCd === 'NORMAL') { 21 + const profile = await Profile.findByUserId(userId);
30 - const doctor = await User.findById(user.doctorId)
31 - result.myDoctor = doctor
32 22
33 - } else if (user.userTypeCd === 'DOCTOR') { 23 + ctx.status = 200;
34 - const patientList = await User.findAllByDoctorId(user.userId) 24 + ctx.body = profile;
35 - result.patientList = patientList
36 25
37 - } else if (user.userTypeCd === 'MANAGER') {
38 - const userList = await User.find()
39 - result.userList = userList
40 - }
41 -
42 - ctx.status = 200
43 - ctx.body = result
44 } 26 }
45 27
46 -exports.getUserDetail = async ctx => { 28 +//toDo
47 - const token = ctx.req.headers.authorization 29 +exports.updateMyInfo = async ctx => {
48 - if (!token || !token.length) { 30 +
49 - ctx.status = 401
50 - return
51 - }
52 -
53 - const { userId } = jwt.verify(token, process.env.JWT_SECRET)
54 - const user = await User.findById(userId)
55 - if(!user) {
56 - ctx.status = 403
57 - return
58 - } else if (user.userTypeCd === 'NORMAL') {
59 - ctx.status = 403
60 - return
61 - }
62 -
63 - let result = {
64 - reqUser : user,
65 - reqUserBottleList : [],
66 - }
67 -
68 - if (user.userTypeCd === 'DOCTOR') {
69 - const { reqUserId } = ctx.params
70 - const reqUser = await User.findById(reqUserId)
71 - if (!reqUser) {
72 - ctx.status = 404
73 - return
74 - }
75 - if(reqUser.doctorId !== user.userId) {
76 - ctx.status = 403
77 - return
78 - }
79 -
80 - const reqUserHubList = await Hub.findAllByUserId(reqUserId)
81 - if(reqUserHubList && reqUserHubList.length) {
82 - const reqUserBottleList = []
83 -
84 - await Promise.all(reqUserHubList.forEach(async hub => {
85 - const bottle = await Bottle.findAllByHubId(hub.hubId)
86 - reqUserBottleList.push(...bottle)
87 - }))
88 -
89 - result.reqUserBottleList = reqUserBottleList
90 - }
91 -
92 - }
93 -
94 - ctx.status = 200
95 - ctx.body = result
96 -
97 } 31 }
98 -
99 -exports.updateReqUser = async ctx => {
100 - const token = ctx.req.headers.authorization
101 - if (!token || !token.length) {
102 - ctx.status = 401
103 - return
104 - }
105 -
106 - const { userId } = jwt.verify(token, process.env.JWT_SECRET)
107 - const user = await User.findById(userId)
108 - if(!user) {
109 - ctx.status = 403
110 - return
111 - }
112 -
113 - if (user.userTypeCd === 'MANAGER') {
114 - const { useYn } = ctx.request.body
115 - const { reqUserId } = ctx.params
116 -
117 - const reqUser = await User.findById(reqUserId)
118 - if(!reqUser) {
119 - ctx.status = 404
120 - return
121 - }
122 -
123 - await reqUser.setUseYn(useYn)
124 - await reqUser.save()
125 -
126 - return
127 - }
128 -
129 - ctx.status = 200
130 -
131 -}
...\ No newline at end of file ...\ No newline at end of file
......
1 const Bottle = require('../models/bottle'); 1 const Bottle = require('../models/bottle');
2 +const History = require('../models/history');
2 3
3 //message subscribe 후 message를 가공한 이후 해당 데이터를 보낼 topic과 message를 리턴하는 함수 4 //message subscribe 후 message를 가공한 이후 해당 데이터를 보낼 topic과 message를 리턴하는 함수
4 exports.dataPublish = async (topic, message) => { 5 exports.dataPublish = async (topic, message) => {
...@@ -65,24 +66,28 @@ const bottleInfoUpdate = async(data) => { ...@@ -65,24 +66,28 @@ const bottleInfoUpdate = async(data) => {
65 humidity = parseFloat(humidity); 66 humidity = parseFloat(humidity);
66 balance = parseInt(balance); 67 balance = parseInt(balance);
67 68
68 - if(isOpen) { 69 + const bottle = await Bottle.findByBottleId(bottleId);
69 - await Bottle.findOneAndUpdate({
70 - bottleId
71 - }, { recentOpen : openDate });
72 - }
73 70
74 - if(balance !== -1) { 71 + if(bottle) {
75 - await Bottle.findOneAndUpdate({ 72 + if(isOpen) {
76 - bottleId 73 + const history = new History({
77 - }, { balance }) 74 + takeDate : new Date(openDate),
75 + bottleId,
76 + medicineId : bottle.getMedicineId(),
77 + });
78 + history.save();
79 + }
80 +
81 + if(balance !== -1) {
82 + await Bottle.findOneAndUpdate({
83 + bottleId
84 + }, { balance })
85 + }
86 +
87 + bottle.updateTemperature(temperature);
88 + bottle.updateHumidity(humidity);
89 + bottle.save();
78 } 90 }
79 -
80 - await Bottle.findOneAndUpdate({
81 - bottleId
82 - }, {
83 - temperature,
84 - humidity
85 - });
86 } 91 }
87 92
88 //해당 MQTT Broker(client)에 bottleId의 정보에 관한 topic과 message를 리턴한다. 93 //해당 MQTT Broker(client)에 bottleId의 정보에 관한 topic과 message를 리턴한다.
......
...@@ -10,7 +10,7 @@ exports.updateMedicineInfo = async() => { ...@@ -10,7 +10,7 @@ exports.updateMedicineInfo = async() => {
10 10
11 //queryUrl을 return하는 함수 : 한 페이지에 100개의 item씩 요청할 수 있다. 11 //queryUrl을 return하는 함수 : 한 페이지에 100개의 item씩 요청할 수 있다.
12 const getQueryURL = (i) => { 12 const getQueryURL = (i) => {
13 - const url = "http://apis.data.go.kr/1471000/DrbEasyDrugInfoService/getDrbEasyDrugList"; 13 + const url = 'http://apis.data.go.kr/1471000/DrbEasyDrugInfoService/getDrbEasyDrugList';
14 const queryParams = '?' + encodeURIComponent('ServiceKey') + '=' + process.env.SERVICE_KEY; 14 const queryParams = '?' + encodeURIComponent('ServiceKey') + '=' + process.env.SERVICE_KEY;
15 const pageNum = '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent(i); 15 const pageNum = '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent(i);
16 const numOfItem = '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent(100); 16 const numOfItem = '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent(100);
......
...@@ -7,10 +7,11 @@ const BottleSchema = new Schema ({ ...@@ -7,10 +7,11 @@ const BottleSchema = new Schema ({
7 temperature : { type : Number, default : 0 }, 7 temperature : { type : Number, default : 0 },
8 humidity : { type : Number, default : 0 }, 8 humidity : { type : Number, default : 0 },
9 balance : { type : Number, default : 0 }, 9 balance : { type : Number, default : 0 },
10 - medicineId : { type : Number, default : null, }, 10 + medicineId : { type : Number, },
11 dosage : { type : Number, default : 0 }, 11 dosage : { type : Number, default : 0 },
12 - hubId : { type : Number, ref : 'Hub' }, 12 + hubId : { type : Number, required : true, },
13 -}) 13 + doctorId : { type : String, default : null, },
14 +});
14 15
15 BottleSchema.statics.findByBottleId = function(bottleId) { 16 BottleSchema.statics.findByBottleId = function(bottleId) {
16 return this.findOne({ bottleId }); 17 return this.findOne({ bottleId });
...@@ -20,14 +21,14 @@ BottleSchema.statics.findAllByHubId = function(hubId) { ...@@ -20,14 +21,14 @@ BottleSchema.statics.findAllByHubId = function(hubId) {
20 return this.find({ hubId }); 21 return this.find({ hubId });
21 }; 22 };
22 23
24 +BottleSchema.statics.findAllByDoctorId = function(doctorId) {
25 + return this.find({ doctorId });
26 +}
27 +
23 BottleSchema.methods.getBottleId = function() { 28 BottleSchema.methods.getBottleId = function() {
24 return this.bottleId; 29 return this.bottleId;
25 }; 30 };
26 31
27 -BottleSchema.methods.getRecentOpenDate = function() {
28 - return this.recentOpen;
29 -};
30 -
31 BottleSchema.methods.getTemperature = function() { 32 BottleSchema.methods.getTemperature = function() {
32 return this.temperature; 33 return this.temperature;
33 }; 34 };
...@@ -52,12 +53,24 @@ BottleSchema.methods.getHubId = function() { ...@@ -52,12 +53,24 @@ BottleSchema.methods.getHubId = function() {
52 return this.hubId; 53 return this.hubId;
53 }; 54 };
54 55
56 +BottleSchema.methods.getDoctorId = function() {
57 + return this.doctorId;
58 +};
59 +
55 BottleSchema.methods.setMedicineId = function(medicineId) { 60 BottleSchema.methods.setMedicineId = function(medicineId) {
56 this.medicineId = medicineId; 61 this.medicineId = medicineId;
57 }; 62 };
58 63
59 -BottleSchema.statics.setDosage = function(dosage) { 64 +BottleSchema.methods.setDosage = function(dosage) {
60 this.dosage = dosage; 65 this.dosage = dosage;
61 }; 66 };
62 67
68 +BottleSchema.methods.updateTemperature = function (temperature) {
69 + this.temperature = temperature;
70 +};
71 +
72 +BottleSchema.methods.updateHumidity = function (humidity) {
73 + this.humidity = humidity;
74 +};
75 +
63 module.exports = mongoose.model('Bottle', BottleSchema); 76 module.exports = mongoose.model('Bottle', BottleSchema);
...\ No newline at end of file ...\ No newline at end of file
......
1 +const mongoose = require('mongoose');
2 +
3 +const Schema = mongoose.Schema;
4 +
5 +const DoctorInfoSchema = new Schema({
6 + doctorId : { type : String, required : true, },
7 + info : {
8 + doctorLicense : { type : String, required : true, },
9 + hospitalNm : { type : String, default : null, },
10 + hosptialAddr : { type : String, default : null, },
11 + contact : { type : String, required : true, },
12 + },
13 + useYn : { type : String, default : 'W', required : true, },
14 +});
15 +
16 +DoctorInfoSchema.statics.findByDoctorId = function(doctorId) {
17 + return this.findOne({ doctorId });
18 +};
19 +
20 +DoctorInfoSchema.methods.setUseYn = function(useYn) {
21 + this.useYn = useYn;
22 +};
23 +
24 +
25 +module.exports = mongoose.model('DoctorInfo', DoctorInfoSchema);
...\ No newline at end of file ...\ No newline at end of file
1 +const mongoose = require('mongoose');
2 +
3 +const Schema = mongoose.Schema;
4 +
5 +const FeedbackSchema = new Schema({
6 + fdbDtm : { type : Date, default : Date.now, required : true, },
7 + fdbType : { type : String, required : true, },
8 + bottleId : { type : Number, required : true, },
9 + doctorId : { type : String, required : true, },
10 + feedback : { type : String, required : true, },
11 +});
12 +
13 +FeedbackSchema.statics.findAllByBottleId = function(bottleId) {
14 + return this.find({ bottleId });
15 +};
16 +
17 +FeedbackSchema.statics.findAllByBottleIdAndDoctorId = function(bottleId, doctorId) {
18 + return this.find({ bottleId, doctorId });
19 +};
20 +
21 +
22 +module.exports = mongoose.model('Feedback', FeedbackSchema);
...\ No newline at end of file ...\ No newline at end of file
1 +const mongoose = require('mongoose');
2 +const moment = require('moment');
3 +
4 +const Schema = mongoose.Schema;
5 +
6 +const PatientInfoSchema = new Schema({
7 + patientId : { type : String, required : true, },
8 + doctorId : { type : String, required : true, },
9 + info : { type : String, required : true, },
10 +});
11 +
12 +PatientInfoSchema.statics.findAllByPatientId = function(patientId) {
13 + return this.find({ patientId });
14 +};
15 +
16 +PatientInfoSchema.statics.findAllByDoctorId = function(doctorId) {
17 + return this.find({ doctorId });
18 +};
19 +
20 +PatientInfoSchema.statics.findByPatientIdAndDoctorId = function(patientId, doctorId) {
21 + return this.findOne({ patientId, doctorId });
22 +};
23 +
24 +PatientInfoSchema.methods.getInfo = function() {
25 + return this.info;
26 +};
27 +
28 +PatientInfoSchema.methods.updateInfo = function(info) {
29 + const date = moment(new Date()).format('YYYY-MM-DD hh:mm');
30 + if(this.info.length)
31 + this.info = this.info.concat('\n\n', `${date} => ${info}`);
32 + else
33 + this.info = `${date} => ${info}`;
34 +};
35 +
36 +
37 +module.exports = mongoose.model('PatientInfo', PatientInfoSchema);
...\ No newline at end of file ...\ No newline at end of file
1 +const mongoose = require('mongoose');
2 +
3 +const Schema = mongoose.Schema;
4 +
5 +const ProfileSchema = new Schema({
6 + userId : { type : String, required : true, },
7 + userNm : { type : String, required : true, },
8 + userAge : { type : Number, required : true, },
9 + contact : { type : String, required : true, },
10 +});
11 +
12 +ProfileSchema.statics.findByUserId = function(userId) {
13 + return this.findOne({ userId });
14 +};
15 +
16 +ProfileSchema.methods.updateUserContact = function(contact) {
17 + this.contact = contact;
18 +};
19 +
20 +ProfileSchema.methods.updateUserAge = function() {
21 + this.userAge = this.userAge + 1;
22 +};
23 +
24 +
25 +module.exports = mongoose.model('Profile', ProfileSchema);
...\ No newline at end of file ...\ No newline at end of file
...@@ -8,8 +8,7 @@ const UserSchema = new Schema ({ ...@@ -8,8 +8,7 @@ const UserSchema = new Schema ({
8 userId : { type: String, required : true, unique : true, lowercase : true }, 8 userId : { type: String, required : true, unique : true, lowercase : true },
9 hashedPassword : { type : String, required : true }, 9 hashedPassword : { type : String, required : true },
10 userTypeCd : { type : String, required : true, default : 'NORMAL' }, 10 userTypeCd : { type : String, required : true, default : 'NORMAL' },
11 - doctorId : { type : String, default : null }, 11 + useYn : { type : String, default : 'W', required : true, },
12 - useYn : { type : Boolean, default : true },
13 }); 12 });
14 13
15 UserSchema.methods.setPassword = async function(password) { 14 UserSchema.methods.setPassword = async function(password) {
...@@ -30,10 +29,6 @@ UserSchema.statics.findByUserId = async function(userId) { ...@@ -30,10 +29,6 @@ UserSchema.statics.findByUserId = async function(userId) {
30 return this.findOne({ userId }); 29 return this.findOne({ userId });
31 }; 30 };
32 31
33 -UserSchema.statics.findAllByDoctorId = async function(doctorId) {
34 - return this.find({ doctorId });
35 -};
36 -
37 UserSchema.statics.findAllByUserTypeCd = async function(userTypeCd) { 32 UserSchema.statics.findAllByUserTypeCd = async function(userTypeCd) {
38 return this.find({ userTypeCd }); 33 return this.find({ userTypeCd });
39 }; 34 };
...@@ -50,4 +45,4 @@ UserSchema.methods.generateToken = function() { ...@@ -50,4 +45,4 @@ UserSchema.methods.generateToken = function() {
50 return token; 45 return token;
51 }; 46 };
52 47
53 -module.exports = mongoose.model("User", UserSchema);
...\ No newline at end of file ...\ No newline at end of file
48 +module.exports = mongoose.model('User', UserSchema);
...\ No newline at end of file ...\ No newline at end of file
......