notification queue
This commit is contained in:
@@ -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}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user