Fix SMS/notification migrations seeding keys before enum values exist
This commit is contained in:
@@ -6,6 +6,17 @@ import {
|
||||
TableIndex,
|
||||
} from 'typeorm';
|
||||
import { NOTIFICATION_SCENARIOS } from '../../notifications/constants/notification-scenarios.constants';
|
||||
import { NotificationScenarioKey } from '../../notifications/enums/notification-scenario-key.enum';
|
||||
|
||||
/** Keys that exist on the enum created in this migration (deposit key is seeded later). */
|
||||
const INITIAL_NOTIFICATION_KEYS = [
|
||||
NotificationScenarioKey.RESERVE_CREATED,
|
||||
NotificationScenarioKey.RESERVE_CONFIRMED,
|
||||
NotificationScenarioKey.RESERVE_CANCELLED,
|
||||
NotificationScenarioKey.RESERVE_REMINDER_SENT,
|
||||
NotificationScenarioKey.CAMPAIGN_SENT,
|
||||
NotificationScenarioKey.CAMPAIGN_FAILED,
|
||||
];
|
||||
|
||||
export class AddNotifications1721500000000 implements MigrationInterface {
|
||||
name = 'AddNotifications1721500000000';
|
||||
@@ -142,11 +153,17 @@ export class AddNotifications1721500000000 implements MigrationInterface {
|
||||
}),
|
||||
);
|
||||
|
||||
for (const scenario of NOTIFICATION_SCENARIOS) {
|
||||
for (const key of INITIAL_NOTIFICATION_KEYS) {
|
||||
const scenario = NOTIFICATION_SCENARIOS.find((item) => item.key === key);
|
||||
if (!scenario) {
|
||||
continue;
|
||||
}
|
||||
|
||||
await queryRunner.query(
|
||||
`
|
||||
INSERT INTO notification_scenario_settings (key, title, body, "isActive")
|
||||
VALUES ($1, $2, $3, true)
|
||||
ON CONFLICT (key) DO NOTHING
|
||||
`,
|
||||
[scenario.key, scenario.defaultTitle, scenario.defaultBody],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user