박권수

Merge branch 'server' into web

/* eslint-disable no-undef */
//회원가입, 로그인 및 로그아웃에 관한 api
const User = require('../../models/user');
const Profile = require('../../models/profile');
......@@ -175,8 +176,8 @@ exports.verifyToken = async(ctx) => {
return;
}
await jwt.verify(token, process.env.JWT_SECRET, (err, decoded) => {
if(err) {
jwt.verify(token, process.env.JWT_SECRET, (err, decoded) => {
if (err) {
ctx.status = 400;
ctx.body = err;
return;
......
......@@ -127,10 +127,29 @@ exports.getPatientDetail = async ctx => {
reqUserBottleList.push(...bottleList);
}));
const reqUserBmList = [];
await Promise.all(reqUserBottleList.map(async bottle => {
const bmList = await BottleMedicine.find({
doctorId : userId,
bottleId : bottle.bottleId,
}).sort({ regDtm : 'desc '}).limit(1);
reqUserBmList.push(...bmList);
}));
const bottleList = await Promise.all(reqUserBmList.map(async bottleMedicine => {
const { dosage, regDtm, medicineId } = bottleMedicine;
const medicine = await Medicine.findOne({ medicineId });
return {
dosage,
regDtm,
medicine,
};
}));
const result = {
profile,
info : isDoctorsPatient.getInfo(),
bottleList : reqUserBottleList,
bottleList,
};
ctx.status = 200;
......@@ -296,6 +315,37 @@ exports.writeReqBottleFeedback = async ctx => {
};
exports.searchPatientById = async ctx => {
const token = ctx.req.headers.authorization;
if (!token || !token.length) {
ctx.status = 401;
return;
}
// eslint-disable-next-line no-undef
const { userId } = jwt.verify(token, process.env.JWT_SECRET);
const user = await User.findByUserId(userId);
if(!user || user.userTypeCd !== 'DOCTOR') {
ctx.status = 403;
return;
}
const { patientId } = ctx.params;
const patient = await User.findByUserId(patientId);
if(!patient || patient.useYn !== 'Y') {
ctx.status = 404;
return;
}
const patientProfile = await Profile.findOne({ userId : patientId });
ctx.status = 200;
ctx.body = {
patientNm : patientProfile.userNm,
patientId,
};
};
/**
* 새로운 환자를 등록한다.
* @param {*} ctx
......
......@@ -53,9 +53,18 @@ doctor.patch('/patient', doctorCtrl.writeReqPatientReport);
*/
doctor.post('/bottle', doctorCtrl.writeReqBottleFeedback);
/**
* 현재 로그인한 유저(의사)가 이메일로 유저를 검색함
* request parameter : patientId
* url : http://localhost:4000/api/doctor/patient/search/:patientId
* return : patient Info(simple)
*/
doctor.get('/patient/search/:patientId', doctorCtrl.searchPatientById);
/**
* 현재 로그인한 유저(의사)의 관리 환자를 등록함.
* request parameter : reqUserId
* request parameter : patientId
* url : http://localhost:4000/doctor/patient
* return : null
*/
......