update: the push service

This commit is contained in:
mahyargdz
2025-07-28 10:14:18 +03:30
parent 4e32eadf9a
commit 1f932e6f7e
2 changed files with 6 additions and 7 deletions
@@ -18,7 +18,7 @@ export class NajvaPushService {
//===============================================
async sendPushNotification(tokens: string[], message: INajvaNotificationMessage): Promise<INajvaPushResponse | null> {
async sendPushNotification(tokens: string[], message: INajvaNotificationMessage) {
if (!tokens || tokens.length === 0) {
this.logger.warn("No tokens provided for push notification");
return null;
@@ -100,7 +100,7 @@ export class NajvaPushService {
}
//===============================================
async sendNotificationToUser(userToken: string, message: INajvaNotificationMessage): Promise<boolean> {
async sendNotificationToUser(userToken: string, message: INajvaNotificationMessage) {
try {
const result = await this.sendPushNotification([userToken], message);
@@ -117,7 +117,7 @@ export class NajvaPushService {
}
//===============================================
async sendNotificationToMultipleUsers(userTokens: string[], message: INajvaNotificationMessage): Promise<{ success: number; failed: number }> {
async sendNotificationToMultipleUsers(userTokens: string[], message: INajvaNotificationMessage) {
try {
const result = await this.sendPushNotification(userTokens, message);
@@ -72,10 +72,9 @@ export class NotificationsService {
...createNotificationDto,
recipient: user,
});
//
await em.persistAndFlush(notification);
// Send push notification if user has a push token
if (user.pushToken) {
await this.sendPushNotificationToUser(user.pushToken, {
title: createNotificationDto.title,
@@ -92,13 +91,13 @@ export class NotificationsService {
//===============================================
async sendPushNotificationToUser(userToken: string, message: INajvaNotificationMessage): Promise<boolean> {
async sendPushNotificationToUser(userToken: string, message: INajvaNotificationMessage) {
return this.najvaPushService.sendNotificationToUser(userToken, message);
}
//===============================================
async sendPushNotificationToMultipleUsers(userTokens: string[], message: INajvaNotificationMessage): Promise<{ success: number; failed: number }> {
async sendPushNotificationToMultipleUsers(userTokens: string[], message: INajvaNotificationMessage) {
return this.najvaPushService.sendNotificationToMultipleUsers(userTokens, message);
}