박권수

feat. validate doctor license 수정 및, 검증 자격번호 인증 추가

......@@ -155,7 +155,7 @@ exports.acceptDoctorRegReq = async ctx => {
}
try {
const { doctorId } = ctx.request.body;
const { doctorId, validateDoctorLicense } = ctx.request.body;
const doctor = await User.findOne({ userId : doctorId });
if(!doctor) {
ctx.status = 404;
......@@ -181,8 +181,26 @@ exports.acceptDoctorRegReq = async ctx => {
error : '의사로 가입된 회원이 아닙니다.',
};
return;
} else if(!validateDoctorLicense) {
ctx.status = 400;
ctx.body = {
error : '유효한 자격 번호가 아닙니다.',
};
return;
}
const existDoctorInfo = await DoctorInfo.findOne({
'info.validateDoctorLicense' : validateDoctorLicense
});
if(existDoctorInfo) {
ctx.status = 403;
ctx.body = {
error : '중복된 자격번호입니다.',
};
return;
}
const doctorInfo = await DoctorInfo.findOne({
doctorId,
useYn : 'W',
......@@ -190,7 +208,9 @@ exports.acceptDoctorRegReq = async ctx => {
doctor.setUseYn('Y');
doctor.save();
doctorInfo.setUseYn('Y');
doctorInfo.setValidateDoctorLicense(validateDoctorLicense);
doctorInfo.save();
ctx.status = 200;
......@@ -296,12 +316,12 @@ exports.validateDoctorLicense = async ctx => {
return;
}
const { doctorLicense } = ctx.request.body;
const doctorInfo = await DoctorInfo.find({ 'info.doctorLicense' : doctorLicense });
const { validateDoctorLicense } = ctx.request.body;
const doctorInfo = await DoctorInfo.findOne({ 'info.validateDoctorLicense' : validateDoctorLicense });
ctx.status = 200;
ctx.body = {
result : doctorInfo.length > 1 ? false : true,
result : doctorInfo ? false : true,
};
};
......
......@@ -6,6 +6,7 @@ const DoctorInfoSchema = new Schema({
doctorId : { type : String, required : true, },
info : {
doctorLicense : { type : String, required : true, },
validateDoctorLicense : { type : String, default : null },
hospitalNm : { type : String, default : null, },
hospitalAddr : { type : String, default : null, },
contact : { type : String, required : true, },
......@@ -23,5 +24,9 @@ DoctorInfoSchema.methods.setUseYn = function(useYn) {
this.useYn = useYn;
};
DoctorInfoSchema.methods.setValidateDoctorLicense = function(validateDoctorLicense) {
this.info.validateDoctorLicense = validateDoctorLicense;
};
module.exports = mongoose.model('DoctorInfo', DoctorInfoSchema);
......