Fix SMS/notification migrations seeding keys before enum values exist
This commit is contained in:
@@ -6,6 +6,16 @@ import {
|
|||||||
TableIndex,
|
TableIndex,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
import { SMS_SCENARIOS } from '../../sms-settings/constants/sms-scenarios.constants';
|
import { SMS_SCENARIOS } from '../../sms-settings/constants/sms-scenarios.constants';
|
||||||
|
import { SmsScenarioKey } from '../../sms-settings/enums/sms-scenario-key.enum';
|
||||||
|
|
||||||
|
/** Keys that exist on the enum created in this migration (later keys are seeded elsewhere). */
|
||||||
|
const INITIAL_SCENARIO_KEYS = [
|
||||||
|
SmsScenarioKey.OTP_LOGIN,
|
||||||
|
SmsScenarioKey.RESERVE_CREATED,
|
||||||
|
SmsScenarioKey.RESERVE_REMINDER,
|
||||||
|
SmsScenarioKey.RESERVE_CONFIRMED,
|
||||||
|
SmsScenarioKey.RESERVE_CANCELLED,
|
||||||
|
];
|
||||||
|
|
||||||
export class AddSmsScenarioSettings1721200000000 implements MigrationInterface {
|
export class AddSmsScenarioSettings1721200000000 implements MigrationInterface {
|
||||||
name = 'AddSmsScenarioSettings1721200000000';
|
name = 'AddSmsScenarioSettings1721200000000';
|
||||||
@@ -67,11 +77,17 @@ export class AddSmsScenarioSettings1721200000000 implements MigrationInterface {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const scenario of SMS_SCENARIOS) {
|
for (const key of INITIAL_SCENARIO_KEYS) {
|
||||||
|
const scenario = SMS_SCENARIOS.find((item) => item.key === key);
|
||||||
|
if (!scenario) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
await queryRunner.query(
|
await queryRunner.query(
|
||||||
`
|
`
|
||||||
INSERT INTO sms_scenario_settings (key, body, "isActive")
|
INSERT INTO sms_scenario_settings (key, body, "isActive")
|
||||||
VALUES ($1, $2, true)
|
VALUES ($1, $2, true)
|
||||||
|
ON CONFLICT (key) DO NOTHING
|
||||||
`,
|
`,
|
||||||
[scenario.key, scenario.defaultBody],
|
[scenario.key, scenario.defaultBody],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,6 +6,17 @@ import {
|
|||||||
TableIndex,
|
TableIndex,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
import { NOTIFICATION_SCENARIOS } from '../../notifications/constants/notification-scenarios.constants';
|
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 {
|
export class AddNotifications1721500000000 implements MigrationInterface {
|
||||||
name = 'AddNotifications1721500000000';
|
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(
|
await queryRunner.query(
|
||||||
`
|
`
|
||||||
INSERT INTO notification_scenario_settings (key, title, body, "isActive")
|
INSERT INTO notification_scenario_settings (key, title, body, "isActive")
|
||||||
VALUES ($1, $2, $3, true)
|
VALUES ($1, $2, $3, true)
|
||||||
|
ON CONFLICT (key) DO NOTHING
|
||||||
`,
|
`,
|
||||||
[scenario.key, scenario.defaultTitle, scenario.defaultBody],
|
[scenario.key, scenario.defaultTitle, scenario.defaultBody],
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user