Showing
3 changed files
with
26 additions
and
9 deletions
... | @@ -15,6 +15,7 @@ const jwt = require('jsonwebtoken'); | ... | @@ -15,6 +15,7 @@ const jwt = require('jsonwebtoken'); |
15 | 15 | ||
16 | const { uploadQrCode, viewQrCode } = require('../../util/GoogleCloudStorage'); | 16 | const { uploadQrCode, viewQrCode } = require('../../util/GoogleCloudStorage'); |
17 | const QrCodeUtil = require('../../util/QrCodeUtil'); | 17 | const QrCodeUtil = require('../../util/QrCodeUtil'); |
18 | +const { sendPushMessage } = require('../../util/FCM'); | ||
18 | 19 | ||
19 | 20 | ||
20 | /** | 21 | /** |
... | @@ -341,7 +342,19 @@ exports.writeReqBottleFeedback = async ctx => { | ... | @@ -341,7 +342,19 @@ exports.writeReqBottleFeedback = async ctx => { |
341 | doctorId : userId, | 342 | doctorId : userId, |
342 | feedback, | 343 | feedback, |
343 | }); | 344 | }); |
344 | - newFeedback.save(); | 345 | + await newFeedback.save(); |
346 | + | ||
347 | + | ||
348 | + //feedback 알람 보내기 | ||
349 | + const hub = await Hub.findOne({ hubId : bottle.hubId }); | ||
350 | + const patientProfile = await Profile.findOne({ userId : hub.userId }); | ||
351 | + if(patientProfile) { | ||
352 | + sendPushMessage({ | ||
353 | + deviceToken : patientProfile.deviceToken, | ||
354 | + title : '의사에게 새로운 알람이 도착했습니다.', | ||
355 | + body : feedback, | ||
356 | + }); | ||
357 | + } | ||
345 | 358 | ||
346 | ctx.status = 200; | 359 | ctx.status = 200; |
347 | 360 | ... | ... |
... | @@ -62,7 +62,8 @@ exports.pushNotifyByDosage = async() => { | ... | @@ -62,7 +62,8 @@ exports.pushNotifyByDosage = async() => { |
62 | const medicine = await Medicine.findOne({ medicineId : bottleMedicine.medicineId }); | 62 | const medicine = await Medicine.findOne({ medicineId : bottleMedicine.medicineId }); |
63 | pushNotify({ | 63 | pushNotify({ |
64 | deviceToken, | 64 | deviceToken, |
65 | - message : medicine.name + '을 복용하셔야 합니다.', | 65 | + title : '약 복용 시간입니다', |
66 | + body : medicine.name + '을 복용하셔야 합니다.', | ||
66 | }); | 67 | }); |
67 | } | 68 | } |
68 | } | 69 | } |
... | @@ -88,7 +89,8 @@ exports.pushNotifyByDosage = async() => { | ... | @@ -88,7 +89,8 @@ exports.pushNotifyByDosage = async() => { |
88 | const medicine = await Medicine.findOne({ medicineId : bottleMedicine.medicineId }); | 89 | const medicine = await Medicine.findOne({ medicineId : bottleMedicine.medicineId }); |
89 | pushNotify({ | 90 | pushNotify({ |
90 | deviceToken, | 91 | deviceToken, |
91 | - message : medicine.name + '을 복용하셔야 합니다.', | 92 | + title : '약 복용 시간입니다', |
93 | + body : medicine.name + '을 복용하셔야 합니다.', | ||
92 | }); | 94 | }); |
93 | } | 95 | } |
94 | } | 96 | } |
... | @@ -114,7 +116,8 @@ exports.pushNotifyByDosage = async() => { | ... | @@ -114,7 +116,8 @@ exports.pushNotifyByDosage = async() => { |
114 | const medicine = await Medicine.findOne({ medicineId : bottleMedicine.medicineId }); | 116 | const medicine = await Medicine.findOne({ medicineId : bottleMedicine.medicineId }); |
115 | pushNotify({ | 117 | pushNotify({ |
116 | deviceToken, | 118 | deviceToken, |
117 | - message : medicine.name + '을 복용하셔야 합니다.', | 119 | + title : '약 복용 시간입니다', |
120 | + body : medicine.name + '을 복용하셔야 합니다.', | ||
118 | }); | 121 | }); |
119 | } | 122 | } |
120 | } | 123 | } |
... | @@ -125,10 +128,11 @@ exports.pushNotifyByDosage = async() => { | ... | @@ -125,10 +128,11 @@ exports.pushNotifyByDosage = async() => { |
125 | 128 | ||
126 | }; | 129 | }; |
127 | 130 | ||
128 | -const pushNotify = ({ deviceToken, message }) => { | 131 | +const pushNotify = ({ deviceToken, title, body }) => { |
129 | //toDo : deviceToken을 받아서 push notification을 발송하는 함수 | 132 | //toDo : deviceToken을 받아서 push notification을 발송하는 함수 |
130 | sendPushMessage({ | 133 | sendPushMessage({ |
131 | deviceToken, | 134 | deviceToken, |
132 | - message, | 135 | + title, |
136 | + body, | ||
133 | }); | 137 | }); |
134 | }; | 138 | }; | ... | ... |
... | @@ -7,11 +7,11 @@ exports.initializeFCM = () => { | ... | @@ -7,11 +7,11 @@ exports.initializeFCM = () => { |
7 | }); | 7 | }); |
8 | }; | 8 | }; |
9 | 9 | ||
10 | -exports.sendPushMessage = async ({ deviceToken, message }) => { | 10 | +exports.sendPushMessage = async ({ deviceToken, title, body }) => { |
11 | const notifyMessage = { | 11 | const notifyMessage = { |
12 | notification : { | 12 | notification : { |
13 | - title : '약 먹을 시간입니다', | 13 | + title, |
14 | - body : message, | 14 | + body, |
15 | }, | 15 | }, |
16 | token : deviceToken, | 16 | token : deviceToken, |
17 | }; | 17 | }; | ... | ... |
-
Please register or login to post a comment