박권수

feat. feedback 작성 시push notification 전송

......@@ -15,6 +15,7 @@ const jwt = require('jsonwebtoken');
const { uploadQrCode, viewQrCode } = require('../../util/GoogleCloudStorage');
const QrCodeUtil = require('../../util/QrCodeUtil');
const { sendPushMessage } = require('../../util/FCM');
/**
......@@ -341,7 +342,19 @@ exports.writeReqBottleFeedback = async ctx => {
doctorId : userId,
feedback,
});
newFeedback.save();
await newFeedback.save();
//feedback 알람 보내기
const hub = await Hub.findOne({ hubId : bottle.hubId });
const patientProfile = await Profile.findOne({ userId : hub.userId });
if(patientProfile) {
sendPushMessage({
deviceToken : patientProfile.deviceToken,
title : '의사에게 새로운 알람이 도착했습니다.',
body : feedback,
});
}
ctx.status = 200;
......
......@@ -62,7 +62,8 @@ exports.pushNotifyByDosage = async() => {
const medicine = await Medicine.findOne({ medicineId : bottleMedicine.medicineId });
pushNotify({
deviceToken,
message : medicine.name + '을 복용하셔야 합니다.',
title : '약 복용 시간입니다',
body : medicine.name + '을 복용하셔야 합니다.',
});
}
}
......@@ -88,7 +89,8 @@ exports.pushNotifyByDosage = async() => {
const medicine = await Medicine.findOne({ medicineId : bottleMedicine.medicineId });
pushNotify({
deviceToken,
message : medicine.name + '을 복용하셔야 합니다.',
title : '약 복용 시간입니다',
body : medicine.name + '을 복용하셔야 합니다.',
});
}
}
......@@ -114,7 +116,8 @@ exports.pushNotifyByDosage = async() => {
const medicine = await Medicine.findOne({ medicineId : bottleMedicine.medicineId });
pushNotify({
deviceToken,
message : medicine.name + '을 복용하셔야 합니다.',
title : '약 복용 시간입니다',
body : medicine.name + '을 복용하셔야 합니다.',
});
}
}
......@@ -125,10 +128,11 @@ exports.pushNotifyByDosage = async() => {
};
const pushNotify = ({ deviceToken, message }) => {
const pushNotify = ({ deviceToken, title, body }) => {
//toDo : deviceToken을 받아서 push notification을 발송하는 함수
sendPushMessage({
deviceToken,
message,
title,
body,
});
};
......
......@@ -7,11 +7,11 @@ exports.initializeFCM = () => {
});
};
exports.sendPushMessage = async ({ deviceToken, message }) => {
exports.sendPushMessage = async ({ deviceToken, title, body }) => {
const notifyMessage = {
notification : {
title : '약 먹을 시간입니다',
body : message,
title,
body,
},
token : deviceToken,
};
......