refactor: the user setting and change to be cateogry based
This commit is contained in:
@@ -1,73 +0,0 @@
|
||||
import { MigrationInterface, QueryRunner, TableColumn } from "typeorm";
|
||||
|
||||
export class AddBusinessFieldsToUserSubscription1740574122421 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.addColumns("user_subscription", [
|
||||
new TableColumn({
|
||||
name: "businessName",
|
||||
type: "varchar",
|
||||
length: "250",
|
||||
isNullable: true,
|
||||
default: "'Unknown Business'",
|
||||
}),
|
||||
new TableColumn({
|
||||
name: "businessPhone",
|
||||
type: "varchar",
|
||||
length: "50",
|
||||
isNullable: true,
|
||||
default: "''",
|
||||
}),
|
||||
new TableColumn({
|
||||
name: "description",
|
||||
type: "text",
|
||||
// length: "250",
|
||||
isNullable: true,
|
||||
default: "''",
|
||||
}),
|
||||
]);
|
||||
|
||||
await queryRunner.query(
|
||||
`UPDATE "user_subscription" SET "businessName" = 'Unknown Business', "businessPhone" = '', "description" = '' WHERE "businessName" IS NULL`,
|
||||
);
|
||||
|
||||
await queryRunner.changeColumn(
|
||||
"user_subscription",
|
||||
"businessName",
|
||||
new TableColumn({
|
||||
name: "businessName",
|
||||
type: "varchar",
|
||||
length: "250",
|
||||
isNullable: false,
|
||||
}),
|
||||
);
|
||||
|
||||
await queryRunner.changeColumn(
|
||||
"user_subscription",
|
||||
"businessPhone",
|
||||
new TableColumn({
|
||||
name: "businessPhone",
|
||||
type: "varchar",
|
||||
length: "50",
|
||||
isNullable: false,
|
||||
}),
|
||||
);
|
||||
|
||||
await queryRunner.changeColumn(
|
||||
"user_subscription",
|
||||
"description",
|
||||
new TableColumn({
|
||||
name: "description",
|
||||
type: "text",
|
||||
isNullable: false,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.dropColumns("user_subscription", [
|
||||
new TableColumn({ name: "businessName", type: "varchar" }),
|
||||
new TableColumn({ name: "businessPhone", type: "varchar" }),
|
||||
new TableColumn({ name: "description", type: "text" }),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class SetInvoiceNumericIdStartValue1740742921699 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "invoice" ALTER COLUMN "numericId" RESTART WITH 1000;`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "invoice" ALTER COLUMN "numericId" RESTART WITH 1;`);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,24 @@
|
||||
import { Logger } from "@nestjs/common";
|
||||
import { DataSource } from "typeorm";
|
||||
|
||||
import { NotifSetting } from "../../src/modules/settings/entities/notif-setting.entity";
|
||||
import { FarsiNotifSettingsEnum, NotifSettingsEnum } from "../../src/modules/settings/enums/notif-settings.enum";
|
||||
|
||||
const notifSettings = [
|
||||
{ title: NotifSettingsEnum.ANNOUNCE_NOTIF, title_fa: FarsiNotifSettingsEnum.ANNOUNCE_NOTIF },
|
||||
{ title: NotifSettingsEnum.ANSWER_TICKET, title_fa: FarsiNotifSettingsEnum.ANSWER_TICKET },
|
||||
{ title: NotifSettingsEnum.BILL_PAYMENT, title_fa: FarsiNotifSettingsEnum.BILL_PAYMENT },
|
||||
{ title: NotifSettingsEnum.BILL_PAYMENT_REMINDER, title_fa: FarsiNotifSettingsEnum.BILL_PAYMENT_REMINDER },
|
||||
{ title: NotifSettingsEnum.BLOCKING_SERVICE, title_fa: FarsiNotifSettingsEnum.BLOCKING_SERVICE },
|
||||
{ title: NotifSettingsEnum.CREATE_INVOICE, title_fa: FarsiNotifSettingsEnum.CREATE_INVOICE },
|
||||
{ title: NotifSettingsEnum.CREATE_TICKET, title_fa: FarsiNotifSettingsEnum.CREATE_TICKET },
|
||||
{ title: NotifSettingsEnum.UNBLOCKING_SERVICE, title_fa: FarsiNotifSettingsEnum.UNBLOCKING_SERVICE },
|
||||
{ title: NotifSettingsEnum.CREATE_SERVICE, title_fa: FarsiNotifSettingsEnum.CREATE_SERVICE },
|
||||
];
|
||||
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(NotifSetting);
|
||||
for (const setting of notifSettings) {
|
||||
const newSetting = notifSettingRepo.create(setting);
|
||||
await notifSettingRepo.save(newSetting);
|
||||
}
|
||||
logger.log("Notif Settings Successfully");
|
||||
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 settings", error);
|
||||
logger.error("Error in seeding notification settings", error);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user