박권수

Merge branch 'server' into web

......@@ -8,8 +8,49 @@ const TakeMedicineHist = require('../../models/takeMedicineHistory');
const Feedback = require('../../models/feedback');
const Hub = require('../../models/hub');
const PatientInfo = require('../../models/patientInfo');
const DoctorInfo = require('../../models/doctorInfo');
const jwt = require('jsonwebtoken');
/**
* 현재 로그인한 유저의 의사 정보를 가져온다
* http methods : get
* @param {*} ctx
* @returns
*/
exports.getDoctorsInfo = 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' || user.useYn !== 'Y') {
ctx.status = 403;
return;
}
const doctorInfo = await DoctorInfo.findOne({
doctorId : userId,
useYn : 'Y'
});
if(!doctorInfo) {
ctx.status = 401;
ctx.body = {
error : '인증되지 않은 회원'
}
return;
}
ctx.status = 200;
ctx.body = doctorInfo.info;
};
/**
* 관리하는 환자 목록을 모두 가져옴
* @param {*} ctx
......
......@@ -3,6 +3,15 @@ const doctorCtrl = require('./doctor.ctrl');
const doctor = new Router();
/**
* 현재 로그인한 유저(의사)의 정보를 가져옴.
* request parameter : token
* url : http://localhost:4000/doctor/
* return : doctor's Info
*/
doctor.get('/', doctorCtrl.getDoctorsInfo);
/**
* 현재 로그인한 유저(의사)의 관리 환자 목록을 가져옴
* request parameter
......
......@@ -18,6 +18,7 @@ exports.getMyDetail = async ctx => {
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 || user.useYn !== 'Y') {
......@@ -54,6 +55,7 @@ exports.getMyDoctorList = async ctx => {
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 !== 'NORMAL' || user.useYn !== 'Y') {
......@@ -92,6 +94,7 @@ exports.viewAllDoctorRegisterReq = async ctx => {
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 || user.userTypeCd !== 'NORMAL' || user.useYn !== 'Y') {
......@@ -118,6 +121,7 @@ exports.acceptDoctorRegister = async ctx => {
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 || user.userTypeCd !== 'NORMAL' || user.useYn !== 'Y') {
......