Compare commits
3 commits
dc586e3991
...
1cc35a57c9
Author | SHA1 | Date | |
---|---|---|---|
1cc35a57c9 | |||
e4da0f59b3 | |||
d6bd2308a1 |
2 changed files with 19 additions and 21 deletions
|
@ -134,10 +134,10 @@ module.exports = async function () {
|
|||
const { reason, alertId, userId: alertingUserId } = alertingRow
|
||||
logger.debug({ reason, alertId, alertingUserId }, "Found alerting record")
|
||||
|
||||
const devices = []
|
||||
let devicesList
|
||||
if (reason === "relative") {
|
||||
logger.debug({ alertingUserId }, "Querying device record for user")
|
||||
const devicesList = await sql`
|
||||
devicesList = await sql`
|
||||
SELECT
|
||||
"id",
|
||||
"fcm_token" as "fcmToken",
|
||||
|
@ -148,33 +148,21 @@ module.exports = async function () {
|
|||
"user_id" = ${alertingUserId}
|
||||
AND "fcm_token" IS NOT NULL
|
||||
`
|
||||
devices.push(...devicesList.map((device) => ({ ...device })))
|
||||
} else {
|
||||
const { deviceId } = alertingRow
|
||||
logger.debug({ deviceId }, "Querying device record")
|
||||
const [device] = await sql`
|
||||
devicesList = await sql`
|
||||
SELECT
|
||||
"fcm_token" as "fcmToken",
|
||||
"notification_alert_level" as "notificationAlertLevel"
|
||||
FROM
|
||||
"device"
|
||||
WHERE
|
||||
"id" = ${deviceId}
|
||||
"user_id" = ${alertingUserId}
|
||||
AND "fcm_token" IS NOT NULL
|
||||
`
|
||||
if (device) {
|
||||
devices.push({ id: deviceId, ...device })
|
||||
}
|
||||
}
|
||||
|
||||
let sentOnce = false
|
||||
await async.allLimit(devices, MAX_PARALLEL_PUSHES, async (device) => {
|
||||
const { id: deviceId, fcmToken } = device
|
||||
const notificationAlertLevel = device.notificationAlertLevel || "green"
|
||||
logger.debug(
|
||||
{ deviceId, notificationAlertLevel },
|
||||
"Found device record"
|
||||
)
|
||||
const devices = devicesList.map((device) => ({ ...device }))
|
||||
|
||||
logger.debug({ alertId }, "Querying alert record")
|
||||
const [{ userId: alertUserId, level, code }] = await sql`
|
||||
|
@ -188,6 +176,16 @@ module.exports = async function () {
|
|||
"alert"."id" = ${alertId}
|
||||
`
|
||||
|
||||
let sentOnce = false
|
||||
|
||||
await async.allLimit(devices, MAX_PARALLEL_PUSHES, async (device) => {
|
||||
const { id: deviceId, fcmToken } = device
|
||||
const notificationAlertLevel = device.notificationAlertLevel || "green"
|
||||
logger.debug(
|
||||
{ deviceId, notificationAlertLevel },
|
||||
"Found device record"
|
||||
)
|
||||
|
||||
if (alertUserId === alertingUserId) {
|
||||
logger.info(
|
||||
{ alertUserId, alertingUserId },
|
||||
|
|
|
@ -29,7 +29,7 @@ module.exports = async function () {
|
|||
"id" = ${alertId}
|
||||
`
|
||||
|
||||
if (alert) {
|
||||
if (!alert) {
|
||||
// alert removed
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue