create notification prefrences in setup rest
This commit is contained in:
@@ -13,6 +13,8 @@ import { Admin } from '../../admin/entities/admin.entity';
|
||||
import { AdminRole } from '../../admin/entities/adminRole.entity';
|
||||
import { Role } from '../../roles/entities/role.entity';
|
||||
import { normalizePhone } from 'src/modules/utils/phone.util';
|
||||
import { NotificationPreference } from '../../notifications/entities/notification-preference.entity';
|
||||
import { notificationPreferencesData } from '../../../seeders/data/notification-preferences.data';
|
||||
|
||||
@Injectable()
|
||||
export class RestaurantsService {
|
||||
@@ -59,8 +61,8 @@ export class RestaurantsService {
|
||||
if (!admin) {
|
||||
admin = em.create(Admin, {
|
||||
phone: normalizedPhone,
|
||||
firstName: 'نام مدیر',
|
||||
lastName: 'نام خانوادگی مدیر',
|
||||
firstName: '[نام]',
|
||||
lastName: '[نام خانوادگی]',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -71,8 +73,17 @@ export class RestaurantsService {
|
||||
restaurant,
|
||||
});
|
||||
|
||||
// Create notification preferences for the restaurant
|
||||
const notificationPreferences = notificationPreferencesData.map(preferenceData =>
|
||||
em.create(NotificationPreference, {
|
||||
restaurant,
|
||||
title: preferenceData.title,
|
||||
channels: preferenceData.channels,
|
||||
})
|
||||
);
|
||||
|
||||
// Persist all entities
|
||||
em.persist([restaurant, admin, adminRole]);
|
||||
em.persist([restaurant, admin, adminRole, ...notificationPreferences]);
|
||||
await em.flush();
|
||||
|
||||
return restaurant;
|
||||
|
||||
Reference in New Issue
Block a user