chore: update the push notif and create notif to fire and forgot the najva service

This commit is contained in:
mahyargdz
2025-07-30 10:23:15 +03:30
parent f46c2ced99
commit 136db8fef4
@@ -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);