박권수

feat. eslint style change, get Doctor's info api

...@@ -8,8 +8,49 @@ const TakeMedicineHist = require('../../models/takeMedicineHistory'); ...@@ -8,8 +8,49 @@ const TakeMedicineHist = require('../../models/takeMedicineHistory');
8 const Feedback = require('../../models/feedback'); 8 const Feedback = require('../../models/feedback');
9 const Hub = require('../../models/hub'); 9 const Hub = require('../../models/hub');
10 const PatientInfo = require('../../models/patientInfo'); 10 const PatientInfo = require('../../models/patientInfo');
11 +const DoctorInfo = require('../../models/doctorInfo');
11 const jwt = require('jsonwebtoken'); 12 const jwt = require('jsonwebtoken');
12 13
14 +
15 +/**
16 + * 현재 로그인한 유저의 의사 정보를 가져온다
17 + * http methods : get
18 + * @param {*} ctx
19 + * @returns
20 + */
21 +exports.getDoctorsInfo = async ctx => {
22 + const token = ctx.req.headers.authorization;
23 + if(!token || !token.length) {
24 + ctx.status = 401;
25 + return;
26 + }
27 +
28 + // eslint-disable-next-line no-undef
29 + const { userId } = jwt.verify(token, process.env.JWT_SECRET);
30 + const user = await User.findByUserId(userId);
31 + if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') {
32 + ctx.status = 403;
33 + return;
34 + }
35 +
36 + const doctorInfo = await DoctorInfo.find({
37 + doctorId : userId,
38 + useYn : 'Y'
39 + });
40 +
41 + if(!doctorInfo) {
42 + ctx.status = 401;
43 + ctx.body = {
44 + error : '인증되지 않은 회원'
45 + }
46 + return;
47 + }
48 +
49 + ctx.status = 200;
50 + ctx.body = doctorInfo;
51 +
52 +};
53 +
13 /** 54 /**
14 * 관리하는 환자 목록을 모두 가져옴 55 * 관리하는 환자 목록을 모두 가져옴
15 * @param {*} ctx 56 * @param {*} ctx
......
...@@ -3,6 +3,15 @@ const doctorCtrl = require('./doctor.ctrl'); ...@@ -3,6 +3,15 @@ const doctorCtrl = require('./doctor.ctrl');
3 3
4 const doctor = new Router(); 4 const doctor = new Router();
5 5
6 +
7 +/**
8 + * 현재 로그인한 유저(의사)의 정보를 가져옴.
9 + * request parameter : token
10 + * url : http://localhost:4000/doctor/
11 + * return : doctor's Info
12 + */
13 +doctor.get('/', doctorCtrl.getDoctorsInfo);
14 +
6 /** 15 /**
7 * 현재 로그인한 유저(의사)의 관리 환자 목록을 가져옴 16 * 현재 로그인한 유저(의사)의 관리 환자 목록을 가져옴
8 * request parameter 17 * request parameter
......
...@@ -18,6 +18,7 @@ exports.getMyDetail = async ctx => { ...@@ -18,6 +18,7 @@ exports.getMyDetail = async ctx => {
18 return 18 return
19 } 19 }
20 20
21 + // eslint-disable-next-line no-undef
21 const { userId } = jwt.verify(token, process.env.JWT_SECRET) 22 const { userId } = jwt.verify(token, process.env.JWT_SECRET)
22 const user = await User.findByUserId(userId) 23 const user = await User.findByUserId(userId)
23 if(!user || !user.userTypeCd || user.useYn !== 'Y') { 24 if(!user || !user.userTypeCd || user.useYn !== 'Y') {
...@@ -54,6 +55,7 @@ exports.getMyDoctorList = async ctx => { ...@@ -54,6 +55,7 @@ exports.getMyDoctorList = async ctx => {
54 return 55 return
55 } 56 }
56 57
58 + // eslint-disable-next-line no-undef
57 const { userId } = jwt.verify(token, process.env.JWT_SECRET) 59 const { userId } = jwt.verify(token, process.env.JWT_SECRET)
58 const user = await User.findByUserId(userId) 60 const user = await User.findByUserId(userId)
59 if(!user || user.userTypeCd !== 'NORMAL' || user.useYn !== 'Y') { 61 if(!user || user.userTypeCd !== 'NORMAL' || user.useYn !== 'Y') {
...@@ -92,6 +94,7 @@ exports.viewAllDoctorRegisterReq = async ctx => { ...@@ -92,6 +94,7 @@ exports.viewAllDoctorRegisterReq = async ctx => {
92 return 94 return
93 } 95 }
94 96
97 + // eslint-disable-next-line no-undef
95 const { userId } = jwt.verify(token, process.env.JWT_SECRET) 98 const { userId } = jwt.verify(token, process.env.JWT_SECRET)
96 const user = await User.findByUserId(userId) 99 const user = await User.findByUserId(userId)
97 if(!user || !user.userTypeCd || user.userTypeCd !== 'NORMAL' || user.useYn !== 'Y') { 100 if(!user || !user.userTypeCd || user.userTypeCd !== 'NORMAL' || user.useYn !== 'Y') {
...@@ -118,6 +121,7 @@ exports.acceptDoctorRegister = async ctx => { ...@@ -118,6 +121,7 @@ exports.acceptDoctorRegister = async ctx => {
118 return 121 return
119 } 122 }
120 123
124 + // eslint-disable-next-line no-undef
121 const { userId } = jwt.verify(token, process.env.JWT_SECRET) 125 const { userId } = jwt.verify(token, process.env.JWT_SECRET)
122 const user = await User.findByUserId(userId) 126 const user = await User.findByUserId(userId)
123 if(!user || !user.userTypeCd || user.userTypeCd !== 'NORMAL' || user.useYn !== 'Y') { 127 if(!user || !user.userTypeCd || user.userTypeCd !== 'NORMAL' || user.useYn !== 'Y') {
......