박권수

fix. merge conflict

...@@ -7,95 +7,98 @@ ...@@ -7,95 +7,98 @@
7 * 2) Dosage에 따라, Push Notification 발송 7 * 2) Dosage에 따라, Push Notification 발송
8 */ 8 */
9 9
10 -const cron = require('node-cron'); 10 + const cron = require('node-cron');
11 - 11 +
12 -const Profile = require('../models/profile'); 12 + const Profile = require('../models/profile');
13 -const User = require('../models/user'); 13 + const User = require('../models/user');
14 -const Hub = require('../models/hub'); 14 + const Hub = require('../models/hub');
15 -const Bottle = require('../models/bottle'); 15 + const Bottle = require('../models/bottle');
16 -const BottleMedicine = require('../models/bottleMedicine'); 16 + const BottleMedicine = require('../models/bottleMedicine');
17 - 17 +
18 - 18 +
19 -//매년 1월 1일 00시 00분에 1살씩 추가 19 + //매년 1월 1일 00시 00분에 1살씩 추가
20 -exports.CheckNewYear = () => { 20 + exports.CheckNewYear = () => {
21 - cron.schedule('0 0 0 1 1 *', async () => { 21 + cron.schedule('0 0 0 1 1 *', async () => {
22 - const profileList = await Profile.find(); 22 + const profileList = await Profile.find();
23 - profileList.forEach(async profile => { 23 + profileList.forEach(async profile => {
24 - await profile.updateUserAge(); 24 + await profile.updateUserAge();
25 - profile.save(); 25 + profile.save();
26 - }); 26 + });
27 - 27 +
28 - }, { 28 + }, {
29 - timezone : 'Asia/Tokyo', 29 + timezone : 'Asia/Tokyo',
30 - }); 30 + });
31 -}; 31 + };
32 - 32 +
33 -//dosage에 따라, Push Notification을 발송한다. 33 + //dosage에 따라, Push Notification을 발송한다.
34 -//아침 8시, 점심 12시, 저녁 6시에 한번씩 발송 34 + //아침 8시, 점심 12시, 저녁 6시에 한번씩 발송
35 -exports.PushNotifyByDosage = async() => { 35 + exports.PushNotifyByDosage = async() => {
36 - 36 +
37 - //매일 아침 8시 : 복용량 상관 없이 보냄 37 + //매일 아침 8시 : 복용량 상관 없이 보냄
38 - cron.schedule('0 0 8 * * *', async () => { 38 + cron.schedule('0 0 8 * * *', async () => {
39 - const bottleMedicineList = await BottleMedicine.find({ useYn : 'Y', dosage : { $gte : 1 } }); 39 + const bottleMedicineList = await BottleMedicine.find({ useYn : 'Y', dosage : { $gte : 1 } });
40 - bottleMedicineList.forEach(async bottleMedicine => { 40 + bottleMedicineList.forEach(async bottleMedicine => {
41 - const bottle = await Bottle.findOne({ bottleId : bottleMedicine.bottleId }); 41 + const bottle = await Bottle.findOne({ bottleId : bottleMedicine.bottleId });
42 - const hub = await Hub.findOne({ hubId : bottle.hubId }); 42 + const hub = await Hub.findOne({ hubId : bottle.hubId });
43 - const user = await User.findOne({ userId : hub.userId, useYn : 'Y' }); 43 + const user = await User.findOne({ userId : hub.userId, useYn : 'Y' });
44 - 44 +
45 - if(user) { 45 + if(user) {
46 - const profile = await Profile.findOne({ userId : user.userId }); 46 + const profile = await Profile.findOne({ userId : user.userId });
47 - 47 +
48 - const { deviceToken } = profile; 48 + const { deviceToken } = profile;
49 - PushNotify(deviceToken); 49 + PushNotify(deviceToken);
50 - } 50 + }
51 - }); 51 + });
52 - }, { 52 + }, {
53 - timezone : 'Asia/Tokyo', 53 + timezone : 'Asia/Tokyo',
54 - }); 54 + });
55 - 55 +
56 - 56 +
57 - //매일 점심 12시 : 복용량이 3인 환자들만 57 + //매일 점심 12시 : 복용량이 3인 환자들만
58 - cron.schedule('0 0 12 * * *', async () => { 58 + cron.schedule('0 0 12 * * *', async () => {
59 - const bottleMedicineList = await BottleMedicine.find({ useYn : 'Y', dosage : { $gte : 3 } }); 59 + const bottleMedicineList = await BottleMedicine.find({ useYn : 'Y', dosage : { $gte : 3 } });
60 - bottleMedicineList.forEach(async bottleMedicine => { 60 + bottleMedicineList.forEach(async bottleMedicine => {
61 - const bottle = await Bottle.findOne({ bottleId : bottleMedicine.bottleId }); 61 + const bottle = await Bottle.findOne({ bottleId : bottleMedicine.bottleId });
62 - const hub = await Hub.findOne({ hubId : bottle.hubId }); 62 + const hub = await Hub.findOne({ hubId : bottle.hubId });
63 - const user = await User.findOne({ userId : hub.userId, useYn : 'Y' }); 63 + const user = await User.findOne({ userId : hub.userId, useYn : 'Y' });
64 - 64 +
65 - if(user) { 65 + if(user) {
66 - const profile = await Profile.findOne({ userId : user.userId }); 66 + const profile = await Profile.findOne({ userId : user.userId });
67 - 67 +
68 - const { deviceToken } = profile; 68 + const { deviceToken } = profile;
69 - PushNotify(deviceToken); 69 + PushNotify(deviceToken);
70 - } 70 + }
71 - }); 71 + });
72 - }, { 72 + }, {
73 - timezone : 'Asia/Tokyo', 73 + timezone : 'Asia/Tokyo',
74 - }); 74 + });
75 - 75 +
76 - 76 +
77 - //매일 저녁 6시 77 + //매일 저녁 6시
78 - cron.schedule('0 0 18 * * *', async () => { 78 + cron.schedule('0 0 18 * * *', async () => {
79 - const bottleMedicineList = await BottleMedicine.find({ useYn : 'Y', dosage : { $gte : 2 } }); 79 + const bottleMedicineList = await BottleMedicine.find({ useYn : 'Y', dosage : { $gte : 2 } });
80 - bottleMedicineList.forEach(async bottleMedicine => { 80 + bottleMedicineList.forEach(async bottleMedicine => {
81 - const bottle = await Bottle.findOne({ bottleId : bottleMedicine.bottleId }); 81 + const bottle = await Bottle.findOne({ bottleId : bottleMedicine.bottleId });
82 - const hub = await Hub.findOne({ hubId : bottle.hubId }); 82 + const hub = await Hub.findOne({ hubId : bottle.hubId });
83 - const user = await User.findOne({ userId : hub.userId, useYn : 'Y' }); 83 + const user = await User.findOne({ userId : hub.userId, useYn : 'Y' });
84 - 84 +
85 - if(user) { 85 + if(user) {
86 - const profile = await Profile.findOne({ userId : user.userId }); 86 + const profile = await Profile.findOne({ userId : user.userId });
87 - 87 +
88 - const { deviceToken } = profile; 88 + const { deviceToken } = profile;
89 - PushNotify(deviceToken); 89 + PushNotify(deviceToken);
90 - } 90 + }
91 - }); 91 + });
92 - }, { 92 + }, {
93 - timezone : 'Asia/Tokyo', 93 + timezone : 'Asia/Tokyo',
94 - }); 94 + });
95 - 95 +
96 -}; 96 + };
97 - 97 +
98 -const PushNotify = async(deviceToken) => { 98 + const PushNotify = async(deviceToken) => {
99 //toDo : deviceToken을 받아서 push notification을 발송하는 함수 99 //toDo : deviceToken을 받아서 push notification을 발송하는 함수
100 - console.log(deviceToken); 100 + if(deviceToken) {
101 -}; 101 + console.log(deviceToken);
102 + }
103 + };
104 +
......