From 7e7f49a96b50aaee965ca5704396431e99d38218 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Sun, 28 Jun 2026 23:18:18 +0330 Subject: [PATCH] in-app notif --- .../processors/in-app.processor.ts | 5 +++ .../services/notification.service.ts | 32 +++++++++++++------ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/modules/notifications/processors/in-app.processor.ts b/src/modules/notifications/processors/in-app.processor.ts index 91b35ef..1280fc9 100644 --- a/src/modules/notifications/processors/in-app.processor.ts +++ b/src/modules/notifications/processors/in-app.processor.ts @@ -27,6 +27,11 @@ export class InAppProcessor extends WorkerHost { this.logger.log(`Processing InApp notification - Recipient: ${JSON.stringify(recipient)}, subject: ${subject}`); + if (!recipient.adminId) { + this.logger.warn(`Skipping in-app notification job ${job.id}: missing adminId`); + return; + } + try { this.notificationsGateway.sendInAppNotification( { adminId: recipient.adminId, restaurantId: recipient.restaurantId }, diff --git a/src/modules/notifications/services/notification.service.ts b/src/modules/notifications/services/notification.service.ts index 6c7e243..81c2e7f 100644 --- a/src/modules/notifications/services/notification.service.ts +++ b/src/modules/notifications/services/notification.service.ts @@ -43,16 +43,30 @@ export class NotificationService { return notifications; } - // send in app notification + // send in app notification (admins only — user records must not emit to admin socket rooms) if (preference?.channels?.includes(NotifChannelEnum.IN_APP)) { - await this.queueService.addBulkInAppNotifications( - notifications.map(notification => ({ - recipient: { adminId: notification.admin?.id || '', restaurantId }, - subject: message.title, - body: message.content, - notificationId: notification.id, - })), - ); + const inAppJobs = recipients.flatMap((recipient, index) => { + if (!('adminId' in recipient) || !recipient.adminId) { + return []; + } + + return [ + { + recipient: { adminId: recipient.adminId, restaurantId }, + subject: message.title, + body: message.content, + notificationId: notifications[index]!.id, + }, + ]; + }); + + if (inAppJobs.length > 0) { + await this.queueService.addBulkInAppNotifications(inAppJobs); + } else { + this.logger.warn( + `No admin recipients for in-app notification: restaurant ${restaurantId}, title ${message.title}`, + ); + } } // add sms notifications to queue