박권수

style. code refactoring

......@@ -512,45 +512,28 @@ exports.secession = async ctx => {
}
if(user.userTypeCd === 'NORMAL') {
const profile = await Profile.findOne({ userId });
//프로필 삭제
await profile.setUseYn('N');
await profile.save();
await Profile.updateOne({ userId }, { useYn : 'N' });
//유저에 등록된 허브, 약병, 약병정보 전부 삭제
const hubList = await Hub.find({ userId });
await Promise.all(hubList.map(async hub => {
const bottleList = await Bottle.find({ hubId : hub.hubId });
await Promise.all(bottleList.map(async bottle => {
const bottleMedicine = await BottleMedicine.findOne({ bottleId : bottle.bottleId });
await bottleMedicine.setUseYn('N');
await bottleMedicine.save();
}));
await Bottle.deleteMany({ hubId : hub.hubId });
}));
await Hub.deleteMany({ userId });
//환자 정보 삭제
const patientInfoList = await PatientInfo.find({ patientId : userId, useYn : 'Y' });
await Promise.all(patientInfoList.map(async patientInfo => {
await patientInfo.setUseYn('N');
await patientInfo.save();
}));
await PatientInfo.updateMany({ patientId : userId, useYn : 'Y'}, { useYn : 'N' });
//유저 삭제
await user.setUseYn('N');
await user.save();
} else if (user.userTypeCd === 'DOCTOR') {
const doctorInfo = await DoctorInfo.findOne({ doctorId : userId });
await doctorInfo.setUseYn('WS');
await doctorInfo.save();
//의사 정보 및 환자 정보 삭제
await DoctorInfo.updateOne({ doctorId : userId }, { useYn : 'WS' });
await PatientInfo.updateMany({ doctorId : userId }, { useYn : 'WS' });
await user.setUseYn('WS');
await user.save();
......
const User = require('../../models/user');
const DoctorInfo = require('../../models/doctorInfo');
const PatientInfo = require('../../models/patientInfo');
const jwt = require('jsonwebtoken');
const { viewDoctorLicense } = require('../../util/GoogleCloudStorage');
......@@ -314,18 +315,11 @@ exports.acceptDoctorRegReq = async ctx => {
return;
}
const doctorInfo = await DoctorInfo.findOne({
doctorId,
useYn : 'W',
});
await DoctorInfo.updateOne({ doctorId, useYn : 'W' }, { useYn : 'N' });
await doctor.setUseYn('N');
await doctor.save();
await doctorInfo.setUseYn('N');
await doctorInfo.save();
ctx.status = 200;
} catch(e) {
......@@ -388,17 +382,12 @@ exports.acceptDoctorRegReq = async ctx => {
}
const doctorInfo = await DoctorInfo.findOne({
doctorId,
useYn : 'WS',
});
await DoctorInfo.updateOne({ doctorId, useYn : 'WS' }, { useYn : 'N' });
await PatientInfo.updateMany({ doctorId : userId, useYn : 'WS' }, { useYn : 'N' });
await doctor.setUseYn('N');
await doctor.save();
await doctorInfo.setUseYn('N');
await doctorInfo.save();
ctx.status = 200;
} catch(e) {
......
......@@ -168,7 +168,10 @@ exports.viewAllDoctorRegisterReq = async ctx => {
})
const doctorReqList = await Promise.all(patientInfoList.map(async patientInfo => {
const doctor = await DoctorInfo.findOne({ doctorId : patientInfo.doctorId });
const doctor = await DoctorInfo.findOne({
doctorId : patientInfo.doctorId,
useYn : 'Y',
});
return {
patientId : patientInfo.patientId,
doctorId : patientInfo.doctorId,
......