박권수

feat. bottlemedicine : use Yn add

......@@ -19,7 +19,8 @@
"dependencies": {
"@koa/cors": "^3.1.0",
"moment": "^2.29.1",
"mqtt": "^4.2.6"
"mqtt": "^4.2.6",
"node-cron": "^3.0.0"
},
"devDependencies": {
"eslint": "^7.32.0"
......
......@@ -143,14 +143,11 @@ exports.getBottleInfo = async(ctx) => {
const message = 'req';
await Mqtt.mqttPublishMessage(client, { topic, message });
const bottleMedicine = await BottleMedicine.find({ bottleId })
.sort({ regDtm : 'desc' })
.limit(1);
const bottleMedicine = await BottleMedicine.findOne({ bottleId, useYn : 'Y' });
if(bottleMedicine.length) {
if(bottleMedicine) {
const takeMedicineHist = await TakeMedicineHist
.find({ bmId : bottleMedicine[0]._id })
.find({ bmId : bottleMedicine._id })
.sort({ takeDate : 'desc' })
.populate('bmId');
......@@ -208,12 +205,10 @@ exports.getBottleFeedback = async ctx => {
return;
}
const bottleMedicine = await BottleMedicine.find({ bottleId })
.sort({ regDtm : 'desc' })
.limit(1);
const bottleMedicine = await BottleMedicine.findOne({ bottleId, useYn : 'Y' });
if(bottleMedicine.length) {
const feedbackList = await Feedback.find({ bmId : bottleMedicine[0]._id })
if(bottleMedicine) {
const feedbackList = await Feedback.find({ bmId : bottleMedicine._id })
.sort({ fdbDtm : 'desc' })
.populate('bmId');
......@@ -294,6 +289,7 @@ exports.setMedicine = async(ctx) => {
bottleMedicine.setDoctorId(doctorId);
}
await BottleMedicine.updateMany({ bottleId }, { useYn : 'N '});
bottleMedicine.save();
......
......@@ -145,11 +145,12 @@ exports.getPatientDetail = async ctx => {
const reqUserBmList = [];
await Promise.all(reqUserBottleList.map(async bottle => {
const bmList = await BottleMedicine.find({
const bm = await BottleMedicine.findOne({
doctorId : userId,
bottleId : bottle.bottleId,
}).sort({ regDtm : 'desc' }).limit(1);
reqUserBmList.push(...bmList);
useYn : 'Y',
});
reqUserBmList.push(bm);
}));
const bottleList = await Promise.all(reqUserBmList.map(async bottleMedicine => {
......@@ -207,7 +208,7 @@ exports.getBottleDetail = async ctx => {
return;
}
const bottleMedicine = await BottleMedicine.findOne({ bottleId, doctorId : userId });
const bottleMedicine = await BottleMedicine.findOne({ bottleId, doctorId : userId, useYn : 'Y' });
if(!bottleMedicine) {
ctx.status = 403;
ctx.body = {
......@@ -318,11 +319,9 @@ exports.writeReqBottleFeedback = async ctx => {
return;
}
const bottleMedicine = await BottleMedicine.find({ bottleId, doctorId : userId })
.sort({ regDtm : 'desc' })
.limit(1);
const bottleMedicine = await BottleMedicine.findOne({ bottleId, doctorId : userId, useYn : 'Y' });
if(!bottleMedicine.length) {
if(!bottleMedicine) {
ctx.status = 403;
ctx.body = {
error : '약병에 대한 권한 없음'
......@@ -332,7 +331,7 @@ exports.writeReqBottleFeedback = async ctx => {
const newFeedback = new Feedback({
fdbType,
bmId : bottleMedicine[0]._id,
bmId : bottleMedicine._id,
doctorId : userId,
feedback,
});
......
......@@ -63,7 +63,7 @@ const bottleInfoUpdate = async(data) => {
humidity = parseFloat(humidity);
balance = parseInt(balance);
const bottleMedicine = await BottleMedicine.find({ bottleId }).sort((a, b) => a.regDtm < b.regDtm)[0];
const bottleMedicine = await BottleMedicine.findOne({ bottleId, useYn : 'Y' });
if(bottleMedicine) {
if(isOpen) {
......@@ -83,7 +83,7 @@ const bottleInfoUpdate = async(data) => {
const transPublishingTopicAndMessage = async(bottleId) => {
const topic = 'bottle/' + bottleId + '/stb';
const bottleMedicine = await BottleMedicine.find({ bottleId }).sort((a, b) => a.regDtm < b.regDtm)[0];
const bottleMedicine = await BottleMedicine.findOne({ bottleId, useYn : 'Y' });
const takeMedicineHist = await TakeMedicineHist.find({
bmId : bottleMedicine._id
}).sort((a, b) => a.takeDate < b.takeDate)[0];
......
......@@ -28,11 +28,20 @@ const BottleMedicineSchema = new Schema({
required : true,
default : Date.now,
},
useYn : {
type : String,
required : true,
default : 'Y',
},
});
BottleMedicineSchema.methods.setDoctorId = function(doctorId) {
this.doctorId = doctorId;
};
BottleMedicineSchema.methods.setUseYn = function(useYn) {
this.useYn = useYn;
};
module.exports = mongoose.model('BottleMedicine', BottleMedicineSchema);
\ No newline at end of file
......
......@@ -725,7 +725,14 @@ minimist@^1.1.0, minimist@^1.2.5:
resolved "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz"
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
moment@^2.29.1:
moment-timezone@^0.5.31:
version "0.5.33"
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.33.tgz#b252fd6bb57f341c9b59a5ab61a8e51a73bbd22c"
integrity sha512-PTc2vcT8K9J5/9rDEPe5czSIKgLoGsH8UNpA4qZTVw0Vd/Uz19geE9abbIOQKaAQFcnQ3v5YEXrbSc5BpshH+w==
dependencies:
moment ">= 2.9.0"
"moment@>= 2.9.0", moment@^2.29.1:
version "2.29.1"
resolved "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz"
integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==
......@@ -768,6 +775,13 @@ natural-compare@^1.4.0:
resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz"
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
node-cron@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/node-cron/-/node-cron-3.0.0.tgz#b33252803e430f9cd8590cf85738efa1497a9522"
integrity sha512-DDwIvvuCwrNiaU7HEivFDULcaQualDv7KoNlB/UU1wPW0n1tDEmBJKhEIE6DlF2FuoOHcNbLJ8ITL2Iv/3AWmA==
dependencies:
moment-timezone "^0.5.31"
once@^1.3.0, once@^1.3.1, once@^1.4.0:
version "1.4.0"
resolved "https://registry.npmjs.org/once/-/once-1.4.0.tgz"
......