notification queue

This commit is contained in:
2025-12-13 23:26:07 +03:30
parent 835f2a3853
commit befa311e98
20 changed files with 176 additions and 405 deletions
@@ -4,9 +4,6 @@ import { Notification } from '../entities/notification.entity';
import { NotificationPreferenceService } from './notification-preference.service';
import { NotificationQueueService } from './notification-queue.service';
import { NotificationsGateway } from '../notifications.gateway';
import { NotificationQueueJob } from '../interfaces/notification-queue.interface';
import { Restaurant } from '../../restaurants/entities/restaurant.entity';
import { User } from '../../users/entities/user.entity';
import { NotifChannelEnum, NotifRequest, NotifTitleEnum } from '../interfaces/notification.interface';
@Injectable()
@@ -44,11 +41,12 @@ export class NotificationService {
// send in app notification
if (preference?.channels?.includes(NotifChannelEnum.IN_APP)) {
recipients.forEach(recipient => {
if ('adminId' in recipient) {
notifications.forEach(notif => {
if (notif.admin) {
this.notificationGateway.sendInAppNotification(
{ adminId: recipient.adminId, restaurantId },
{ adminId: notif.admin.id, restaurantId },
{
notificationId: notif.id,
subject: message.title,
body: message.content,
},
@@ -56,32 +54,16 @@ export class NotificationService {
}
});
}
// const job: NotificationQueueJob = {
// restaurantId,
// userId,
// title,
// content,
// // idempotencyKey: finalIdempotencyKey,
// notificationId: notification.id,
// channels: preference.channels,
// };
// preference.channels.forEach(channel => {
// if (channel === NotifChannelEnum.SMS) {
// await this.queueService.addSmsNotification(job);
// } else if (channel === NotifChannelEnum.PUSH) {
// await this.queueService.addPushNotification(job);
// }
// });
// Add to queue
// if (preference.notificationType === NotificationType.SMS) {
// await this.queueService.addSmsNotification(job);
// } else if (preference.notificationType === NotificationType.PUSH) {
// await this.queueService.addPushNotification(job);
// } else if (preference.notificationType === NotificationType.Both) {
// await this.queueService.addSmsNotification(job);
// await this.queueService.addPushNotification(job);
// }
// add sms notifications to queue
if (preference?.channels?.includes(NotifChannelEnum.SMS)) {
await this.queueService.addBulkSmsNotifications(
recipients.map(recipient => ({
recipient,
templateId: message.sms.templateId,
parameters: message.sms.parameters,
})),
);
}
this.logger.log(`Queued notification for restaurant ${restaurantId}, title ${message.title}`);