박권수

feat. validate doctor's license api

......@@ -35,5 +35,13 @@ manage.post('/doctor/accept', manageCtrl.acceptDoctorRegReq);
*/
manage.post('/doctor/reject', manageCtrl.rejectDoctorRegReq);
/**
* 의사 요청을 한 회원의 자격 번호가 유효한지 검증한다
* reqeust parameter : doctor License
* url : http://localhost:4000/api/manage/doctor/validate
* return : result true or false
*/
manage.post('/doctor/validate', manageCtrl.validateDoctorLicense);
module.exports = manage;
\ No newline at end of file
......
......@@ -264,3 +264,33 @@ exports.acceptDoctorRegReq = async ctx => {
}
};
/**
* 회원가입을 요청한 의사의 유효한 자격 번호인지를 검증한다.
* @param {*} ctx
* @returns
*/
exports.validateDoctorLicense = 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 !== 'MANAGER' || user.useYn !== 'Y') {
ctx.status = 403;
return;
}
const { doctorLicense } = ctx.request.body;
const doctorInfo = await DoctorInfo.find({ 'info.doctorLicense' : doctorLicense });
ctx.status = 200;
ctx.body = {
result : doctorInfo.length > 1 ? false : true,
};
};
......