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 { AdminRole } from '../../admin/entities/adminRole.entity';
|
||||||
import { Role } from '../../roles/entities/role.entity';
|
import { Role } from '../../roles/entities/role.entity';
|
||||||
import { normalizePhone } from 'src/modules/utils/phone.util';
|
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()
|
@Injectable()
|
||||||
export class RestaurantsService {
|
export class RestaurantsService {
|
||||||
@@ -59,8 +61,8 @@ export class RestaurantsService {
|
|||||||
if (!admin) {
|
if (!admin) {
|
||||||
admin = em.create(Admin, {
|
admin = em.create(Admin, {
|
||||||
phone: normalizedPhone,
|
phone: normalizedPhone,
|
||||||
firstName: 'نام مدیر',
|
firstName: '[نام]',
|
||||||
lastName: 'نام خانوادگی مدیر',
|
lastName: '[نام خانوادگی]',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,8 +73,17 @@ export class RestaurantsService {
|
|||||||
restaurant,
|
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
|
// Persist all entities
|
||||||
em.persist([restaurant, admin, adminRole]);
|
em.persist([restaurant, admin, adminRole, ...notificationPreferences]);
|
||||||
await em.flush();
|
await em.flush();
|
||||||
|
|
||||||
return restaurant;
|
return restaurant;
|
||||||
|
|||||||
Reference in New Issue
Block a user