From 136db8fef47e17efc9f2f14c25b373fc84c86b55 Mon Sep 17 00:00:00 2001 From: mahyargdz Date: Wed, 30 Jul 2025 10:23:15 +0330 Subject: [PATCH] chore: update the push notif and create notif to fire and forgot the najva service --- .../services/notifications.service.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/modules/notifications/services/notifications.service.ts b/src/modules/notifications/services/notifications.service.ts index 5a24c3e..16fea92 100755 --- a/src/modules/notifications/services/notifications.service.ts +++ b/src/modules/notifications/services/notifications.service.ts @@ -42,8 +42,10 @@ export class NotificationsService { }); await em.persistAndFlush(notification); + await em.commit(); + if (user.pushTokens && user.pushTokens.length > 0) { - await this.sendPushNotificationToUserDevices(user.id, user.pushTokens, { + this.sendPushNotificationAsync(user.id, user.pushTokens, { title: createNotificationDto.title, body: createNotificationDto.message, notification_click: { @@ -52,8 +54,6 @@ export class NotificationsService { }); } - await em.commit(); - return notification; } catch (error) { this.logger.error("error in createNotification", error); @@ -64,6 +64,14 @@ export class NotificationsService { //=============================================== + private sendPushNotificationAsync(userId: string, userTokens: string[], message: INajvaNotificationMessage) { + this.sendPushNotificationToUserDevices(userId, userTokens, message).catch((error) => { + this.logger.error(`Failed to send push notification asynchronously for user ${userId}:`, error); + }); + } + + //=============================================== + async sendPushNotificationToUserDevices(userId: string, userTokens: string[], message: INajvaNotificationMessage) { try { const result = await this.najvaPushService.sendNotificationToMultipleUsers(userTokens, message);