박권수

fix. merge conflict

......@@ -20,7 +20,8 @@
"@koa/cors": "^3.1.0",
"firebase-admin": "^9.11.1",
"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
......
//toDO : Batch System
/**
* 21/09/14
* Author : 박권수
* 배치 시스템
* 1) 매년 지나면 프로필의 Age를 +1
* 2) Dosage에 따라, Push Notification 발송
*/
const cron = require('node-cron');
const Profile = require('../models/profile');
const BottleMedicine = require('../models/bottleMedicine');
\ No newline at end of file
This diff is collapsed. Click to expand it.