fix: multi device lost notifications

This commit is contained in:
devthejo 2025-08-24 13:01:30 +02:00
parent 1cc35a57c9
commit 74e1b5f10b
No known key found for this signature in database
GPG key ID: 00CCA7A92B1D5351

View file

@ -134,34 +134,17 @@ module.exports = async function () {
const { reason, alertId, userId: alertingUserId } = alertingRow
logger.debug({ reason, alertId, alertingUserId }, "Found alerting record")
let devicesList
if (reason === "relative") {
logger.debug({ alertingUserId }, "Querying device record for user")
devicesList = await sql`
SELECT
"id",
"fcm_token" as "fcmToken",
"notification_alert_level" as "notificationAlertLevel"
FROM
"device"
WHERE
"user_id" = ${alertingUserId}
AND "fcm_token" IS NOT NULL
`
} else {
const { deviceId } = alertingRow
logger.debug({ deviceId }, "Querying device record")
devicesList = await sql`
SELECT
"fcm_token" as "fcmToken",
"notification_alert_level" as "notificationAlertLevel"
FROM
"device"
WHERE
"user_id" = ${alertingUserId}
AND "fcm_token" IS NOT NULL
`
}
const devicesList = await sql`
SELECT
"id",
"fcm_token" as "fcmToken",
"notification_alert_level" as "notificationAlertLevel"
FROM
"device"
WHERE
"user_id" = ${alertingUserId}
AND "fcm_token" IS NOT NULL
`
const devices = devicesList.map((device) => ({ ...device }))
logger.debug({ alertId }, "Querying alert record")