25 lines
884 B
TypeScript
Executable File
25 lines
884 B
TypeScript
Executable File
import { Logger } from "@nestjs/common";
|
|
import { DataSource } from "typeorm";
|
|
|
|
import { NotificationSetting } from "../../src/modules/settings/entities/notification-setting.entity";
|
|
import { NotifDescriptions, NotifType } from "../../src/modules/settings/enums/notif-settings.enum";
|
|
|
|
export const seedNotifSettings = async (dataSource: DataSource, logger: Logger) => {
|
|
try {
|
|
const notifSettingRepo = dataSource.getRepository(NotificationSetting);
|
|
|
|
const notifSettings = Object.entries(NotifDescriptions).map(([type, { category, fa }]) => ({
|
|
type: type as NotifType,
|
|
category,
|
|
description: fa,
|
|
}));
|
|
|
|
await notifSettingRepo.insert(notifSettings);
|
|
|
|
logger.log(`Successfully seeded ${notifSettings.length} notification settings.`);
|
|
} catch (error) {
|
|
logger.error("Error in seeding notification settings", error);
|
|
process.exit(1);
|
|
}
|
|
};
|