From 73c91bd9b14bbd9933a96292b4e2e743acfb3899 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 16 May 2024 10:01:59 +0700 Subject: [PATCH] update_table_ProfileAvatar_add_isactive --- src/controllers/ProfileAvatarController.ts | 2 ++ src/entities/ProfileAvatar.ts | 6 +++++ ...update_table_ProfileAvatar_add_isactive.ts | 22 +++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 src/migration/1715828430262-update_table_ProfileAvatar_add_isactive.ts diff --git a/src/controllers/ProfileAvatarController.ts b/src/controllers/ProfileAvatarController.ts index 85b9d70e..4b35f7b6 100644 --- a/src/controllers/ProfileAvatarController.ts +++ b/src/controllers/ProfileAvatarController.ts @@ -32,6 +32,7 @@ export class ProfileAvatarController extends Controller { if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } + result.isActive = true; profile.avatar = result.avatar; profile.avatarName = result.avatarName; return new HttpSuccess(); @@ -59,6 +60,7 @@ export class ProfileAvatarController extends Controller { await this.avatarRepository.save(data); let avatar = `ทะเบียนประวัติ/โปรไฟล์/${profile.id}`; let fileName = `profile-${data.id}`; + data.isActive = true; data.avatar = avatar; data.avatarName = fileName; await this.avatarRepository.save(data); diff --git a/src/entities/ProfileAvatar.ts b/src/entities/ProfileAvatar.ts index 45364479..068ea56c 100644 --- a/src/entities/ProfileAvatar.ts +++ b/src/entities/ProfileAvatar.ts @@ -12,6 +12,12 @@ export class ProfileAvatar extends EntityBase { }) avatar: string; + @Column({ + comment: "สถานะการใช้งาน", + default: false, + }) + isActive: boolean; + @Column({ nullable: true, comment: "รูปถ่าย", diff --git a/src/migration/1715828430262-update_table_ProfileAvatar_add_isactive.ts b/src/migration/1715828430262-update_table_ProfileAvatar_add_isactive.ts new file mode 100644 index 00000000..fe4a419a --- /dev/null +++ b/src/migration/1715828430262-update_table_ProfileAvatar_add_isactive.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableProfileAvatarAddIsactive1715828430262 implements MigrationInterface { + name = 'UpdateTableProfileAvatarAddIsactive1715828430262' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileSalaryEmployee\` DROP COLUMN \`commandNo\``); + await queryRunner.query(`ALTER TABLE \`profileAvatar\` ADD \`isActive\` tinyint NOT NULL COMMENT 'สถานะการใช้งาน' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`profileDiscipline\` DROP FOREIGN KEY \`FK_0031dcb981836876de8524eaff1\``); + await queryRunner.query(`ALTER TABLE \`profileDiscipline\` CHANGE \`profileId\` \`profileId\` varchar(40) NULL COMMENT 'ไอดีโปรไฟล์'`); + await queryRunner.query(`ALTER TABLE \`profileDiscipline\` ADD CONSTRAINT \`FK_0031dcb981836876de8524eaff1\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileDiscipline\` DROP FOREIGN KEY \`FK_0031dcb981836876de8524eaff1\``); + await queryRunner.query(`ALTER TABLE \`profileDiscipline\` CHANGE \`profileId\` \`profileId\` varchar(40) NOT NULL COMMENT 'ไอดีโปรไฟล์'`); + await queryRunner.query(`ALTER TABLE \`profileDiscipline\` ADD CONSTRAINT \`FK_0031dcb981836876de8524eaff1\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`profileAvatar\` DROP COLUMN \`isActive\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryEmployee\` ADD \`commandNo\` text NOT NULL COMMENT 'เลขที่คำสั่ง'`); + } + +}