update notif
This commit is contained in:
@@ -1,26 +1,25 @@
|
||||
import { NotifTitleEnum } from '../../modules/notifications/interfaces/notification.interface';
|
||||
import { NotificationType } from '../../modules/notifications/interfaces/notification.interface';
|
||||
|
||||
import { NotifChannelEnum, NotifTitleEnum } from '../../modules/notifications/interfaces/notification.interface';
|
||||
|
||||
export interface NotificationPreferenceData {
|
||||
title: NotifTitleEnum;
|
||||
notificationType: NotificationType;
|
||||
channels: NotifChannelEnum[];
|
||||
}
|
||||
|
||||
export const notificationPreferencesData: NotificationPreferenceData[] = [
|
||||
{
|
||||
title: NotifTitleEnum.ORDER_CREATED,
|
||||
notificationType: NotificationType.SMS,
|
||||
channels: [NotifChannelEnum.SMS, NotifChannelEnum.PUSH, NotifChannelEnum.IN_APP],
|
||||
},
|
||||
{
|
||||
title: NotifTitleEnum.PAYMENT_SUCCESS,
|
||||
notificationType: NotificationType.SMS,
|
||||
channels: [NotifChannelEnum.SMS, NotifChannelEnum.PUSH, NotifChannelEnum.IN_APP],
|
||||
},
|
||||
{
|
||||
title: NotifTitleEnum.REVIEW_CREATED,
|
||||
notificationType: NotificationType.PUSH,
|
||||
channels: [NotifChannelEnum.SMS, NotifChannelEnum.PUSH, NotifChannelEnum.IN_APP],
|
||||
},
|
||||
{
|
||||
title: NotifTitleEnum.ORDER_STATUS_CHANGED,
|
||||
notificationType: NotificationType.Both,
|
||||
channels: [NotifChannelEnum.SMS, NotifChannelEnum.PUSH, NotifChannelEnum.IN_APP],
|
||||
},
|
||||
];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { EntityManager } from '@mikro-orm/core';
|
||||
import { NotificationPreference } from '../modules/notifications/entities/notification-preference.entity';
|
||||
import { Restaurant } from '../modules/restaurants/entities/restaurant.entity';
|
||||
import type { Restaurant } from '../modules/restaurants/entities/restaurant.entity';
|
||||
import { notificationPreferencesData } from './data/notification-preferences.data';
|
||||
|
||||
export class NotificationPreferencesSeeder {
|
||||
@@ -18,13 +18,13 @@ export class NotificationPreferencesSeeder {
|
||||
const preference = em.create(NotificationPreference, {
|
||||
restaurant,
|
||||
title: preferenceData.title,
|
||||
notificationType: preferenceData.notificationType,
|
||||
channels: preferenceData.channels,
|
||||
});
|
||||
em.persist(preference);
|
||||
} else {
|
||||
// Update existing preference if notification type changed
|
||||
if (existing.notificationType !== preferenceData.notificationType) {
|
||||
existing.notificationType = preferenceData.notificationType;
|
||||
if (existing.channels.length !== preferenceData.channels.length) {
|
||||
existing.channels = preferenceData.channels;
|
||||
em.persist(existing);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user