박권수

fix. merge conflict

...@@ -20,7 +20,8 @@ ...@@ -20,7 +20,8 @@
20 "@koa/cors": "^3.1.0", 20 "@koa/cors": "^3.1.0",
21 "firebase-admin": "^9.11.1", 21 "firebase-admin": "^9.11.1",
22 "moment": "^2.29.1", 22 "moment": "^2.29.1",
23 - "mqtt": "^4.2.6" 23 + "mqtt": "^4.2.6",
24 + "node-cron": "^3.0.0"
24 }, 25 },
25 "devDependencies": { 26 "devDependencies": {
26 "eslint": "^7.32.0" 27 "eslint": "^7.32.0"
......
...@@ -143,14 +143,11 @@ exports.getBottleInfo = async(ctx) => { ...@@ -143,14 +143,11 @@ exports.getBottleInfo = async(ctx) => {
143 const message = 'req'; 143 const message = 'req';
144 await Mqtt.mqttPublishMessage(client, { topic, message }); 144 await Mqtt.mqttPublishMessage(client, { topic, message });
145 145
146 - const bottleMedicine = await BottleMedicine.find({ bottleId }) 146 + const bottleMedicine = await BottleMedicine.findOne({ bottleId, useYn : 'Y' });
147 - .sort({ regDtm : 'desc' })
148 - .limit(1);
149 147
150 - if(bottleMedicine.length) { 148 + if(bottleMedicine) {
151 -
152 const takeMedicineHist = await TakeMedicineHist 149 const takeMedicineHist = await TakeMedicineHist
153 - .find({ bmId : bottleMedicine[0]._id }) 150 + .find({ bmId : bottleMedicine._id })
154 .sort({ takeDate : 'desc' }) 151 .sort({ takeDate : 'desc' })
155 .populate('bmId'); 152 .populate('bmId');
156 153
...@@ -208,12 +205,10 @@ exports.getBottleFeedback = async ctx => { ...@@ -208,12 +205,10 @@ exports.getBottleFeedback = async ctx => {
208 return; 205 return;
209 } 206 }
210 207
211 - const bottleMedicine = await BottleMedicine.find({ bottleId }) 208 + const bottleMedicine = await BottleMedicine.findOne({ bottleId, useYn : 'Y' });
212 - .sort({ regDtm : 'desc' })
213 - .limit(1);
214 209
215 - if(bottleMedicine.length) { 210 + if(bottleMedicine) {
216 - const feedbackList = await Feedback.find({ bmId : bottleMedicine[0]._id }) 211 + const feedbackList = await Feedback.find({ bmId : bottleMedicine._id })
217 .sort({ fdbDtm : 'desc' }) 212 .sort({ fdbDtm : 'desc' })
218 .populate('bmId'); 213 .populate('bmId');
219 214
...@@ -294,6 +289,7 @@ exports.setMedicine = async(ctx) => { ...@@ -294,6 +289,7 @@ exports.setMedicine = async(ctx) => {
294 bottleMedicine.setDoctorId(doctorId); 289 bottleMedicine.setDoctorId(doctorId);
295 } 290 }
296 291
292 + await BottleMedicine.updateMany({ bottleId }, { useYn : 'N '});
297 293
298 bottleMedicine.save(); 294 bottleMedicine.save();
299 295
......
...@@ -145,11 +145,12 @@ exports.getPatientDetail = async ctx => { ...@@ -145,11 +145,12 @@ exports.getPatientDetail = async ctx => {
145 145
146 const reqUserBmList = []; 146 const reqUserBmList = [];
147 await Promise.all(reqUserBottleList.map(async bottle => { 147 await Promise.all(reqUserBottleList.map(async bottle => {
148 - const bmList = await BottleMedicine.find({ 148 + const bm = await BottleMedicine.findOne({
149 doctorId : userId, 149 doctorId : userId,
150 bottleId : bottle.bottleId, 150 bottleId : bottle.bottleId,
151 - }).sort({ regDtm : 'desc' }).limit(1); 151 + useYn : 'Y',
152 - reqUserBmList.push(...bmList); 152 + });
153 + reqUserBmList.push(bm);
153 })); 154 }));
154 155
155 const bottleList = await Promise.all(reqUserBmList.map(async bottleMedicine => { 156 const bottleList = await Promise.all(reqUserBmList.map(async bottleMedicine => {
...@@ -207,7 +208,7 @@ exports.getBottleDetail = async ctx => { ...@@ -207,7 +208,7 @@ exports.getBottleDetail = async ctx => {
207 return; 208 return;
208 } 209 }
209 210
210 - const bottleMedicine = await BottleMedicine.findOne({ bottleId, doctorId : userId }); 211 + const bottleMedicine = await BottleMedicine.findOne({ bottleId, doctorId : userId, useYn : 'Y' });
211 if(!bottleMedicine) { 212 if(!bottleMedicine) {
212 ctx.status = 403; 213 ctx.status = 403;
213 ctx.body = { 214 ctx.body = {
...@@ -318,11 +319,9 @@ exports.writeReqBottleFeedback = async ctx => { ...@@ -318,11 +319,9 @@ exports.writeReqBottleFeedback = async ctx => {
318 return; 319 return;
319 } 320 }
320 321
321 - const bottleMedicine = await BottleMedicine.find({ bottleId, doctorId : userId }) 322 + const bottleMedicine = await BottleMedicine.findOne({ bottleId, doctorId : userId, useYn : 'Y' });
322 - .sort({ regDtm : 'desc' })
323 - .limit(1);
324 323
325 - if(!bottleMedicine.length) { 324 + if(!bottleMedicine) {
326 ctx.status = 403; 325 ctx.status = 403;
327 ctx.body = { 326 ctx.body = {
328 error : '약병에 대한 권한 없음' 327 error : '약병에 대한 권한 없음'
...@@ -332,7 +331,7 @@ exports.writeReqBottleFeedback = async ctx => { ...@@ -332,7 +331,7 @@ exports.writeReqBottleFeedback = async ctx => {
332 331
333 const newFeedback = new Feedback({ 332 const newFeedback = new Feedback({
334 fdbType, 333 fdbType,
335 - bmId : bottleMedicine[0]._id, 334 + bmId : bottleMedicine._id,
336 doctorId : userId, 335 doctorId : userId,
337 feedback, 336 feedback,
338 }); 337 });
......
...@@ -63,7 +63,7 @@ const bottleInfoUpdate = async(data) => { ...@@ -63,7 +63,7 @@ const bottleInfoUpdate = async(data) => {
63 humidity = parseFloat(humidity); 63 humidity = parseFloat(humidity);
64 balance = parseInt(balance); 64 balance = parseInt(balance);
65 65
66 - const bottleMedicine = await BottleMedicine.find({ bottleId }).sort((a, b) => a.regDtm < b.regDtm)[0]; 66 + const bottleMedicine = await BottleMedicine.findOne({ bottleId, useYn : 'Y' });
67 67
68 if(bottleMedicine) { 68 if(bottleMedicine) {
69 if(isOpen) { 69 if(isOpen) {
...@@ -83,7 +83,7 @@ const bottleInfoUpdate = async(data) => { ...@@ -83,7 +83,7 @@ const bottleInfoUpdate = async(data) => {
83 const transPublishingTopicAndMessage = async(bottleId) => { 83 const transPublishingTopicAndMessage = async(bottleId) => {
84 const topic = 'bottle/' + bottleId + '/stb'; 84 const topic = 'bottle/' + bottleId + '/stb';
85 85
86 - const bottleMedicine = await BottleMedicine.find({ bottleId }).sort((a, b) => a.regDtm < b.regDtm)[0]; 86 + const bottleMedicine = await BottleMedicine.findOne({ bottleId, useYn : 'Y' });
87 const takeMedicineHist = await TakeMedicineHist.find({ 87 const takeMedicineHist = await TakeMedicineHist.find({
88 bmId : bottleMedicine._id 88 bmId : bottleMedicine._id
89 }).sort((a, b) => a.takeDate < b.takeDate)[0]; 89 }).sort((a, b) => a.takeDate < b.takeDate)[0];
......
...@@ -28,11 +28,20 @@ const BottleMedicineSchema = new Schema({ ...@@ -28,11 +28,20 @@ const BottleMedicineSchema = new Schema({
28 required : true, 28 required : true,
29 default : Date.now, 29 default : Date.now,
30 }, 30 },
31 + useYn : {
32 + type : String,
33 + required : true,
34 + default : 'Y',
35 + },
31 }); 36 });
32 37
33 BottleMedicineSchema.methods.setDoctorId = function(doctorId) { 38 BottleMedicineSchema.methods.setDoctorId = function(doctorId) {
34 this.doctorId = doctorId; 39 this.doctorId = doctorId;
35 }; 40 };
36 41
42 +BottleMedicineSchema.methods.setUseYn = function(useYn) {
43 + this.useYn = useYn;
44 +};
45 +
37 46
38 module.exports = mongoose.model('BottleMedicine', BottleMedicineSchema); 47 module.exports = mongoose.model('BottleMedicine', BottleMedicineSchema);
...\ No newline at end of file ...\ No newline at end of file
......
1 +//toDO : Batch System
2 +/**
3 + * 21/09/14
4 + * Author : 박권수
5 + * 배치 시스템
6 + * 1) 매년 지나면 프로필의 Age를 +1
7 + * 2) Dosage에 따라, Push Notification 발송
8 + */
9 +
10 +const cron = require('node-cron');
11 +
12 +const Profile = require('../models/profile');
13 +const BottleMedicine = require('../models/bottleMedicine');
...\ No newline at end of file ...\ No newline at end of file
This diff is collapsed. Click to expand it.