From 9a7adc4eb53af91756b4a16c8b2f1d9e483341ca Mon Sep 17 00:00:00 2001 From: Kittapath Date: Mon, 13 May 2024 15:38:56 +0700 Subject: [PATCH] migrate --- src/controllers/ProfileEmployeeController.ts | 10 +++--- ...290-update_table_profileemployee_add_pk.ts | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 src/migration/1715589320290-update_table_profileemployee_add_pk.ts diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 7aa8180b..a553539b 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -256,12 +256,12 @@ export class ProfileEmployeeController extends Controller { : "1=1", ) .andWhere( - type !== undefined && type !== null && type !== "" - ? "profileEmployee.employeeClass LIKE :type" + type !== undefined && type !== null && type !== "" + ? "profileEmployee.employeeClass LIKE :type" : "1=1", { - type: `%${type}%`, - } + type: type == null || type == undefined ? null : `${type.trim().toUpperCase()}`, + }, ) .skip((page - 1) * pageSize) .take(pageSize) @@ -296,7 +296,7 @@ export class ProfileEmployeeController extends Controller { posTypeId: _data.posType == null ? null : _data.posType.id, position: _data.position, posNo: shortName, - employeeClass: _data.employeeClass == null ? null : _data.employeeClass + employeeClass: _data.employeeClass == null ? null : _data.employeeClass, }; }), ); diff --git a/src/migration/1715589320290-update_table_profileemployee_add_pk.ts b/src/migration/1715589320290-update_table_profileemployee_add_pk.ts new file mode 100644 index 00000000..3305e1f7 --- /dev/null +++ b/src/migration/1715589320290-update_table_profileemployee_add_pk.ts @@ -0,0 +1,32 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableProfileemployeeAddPk1715589320290 implements MigrationInterface { + name = 'UpdateTableProfileemployeeAddPk1715589320290' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileCertificate\` ADD \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee'`); + await queryRunner.query(`ALTER TABLE \`profileTraining\` ADD \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee'`); + await queryRunner.query(`ALTER TABLE \`profileInsignia\` ADD \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee'`); + await queryRunner.query(`ALTER TABLE \`profileHonor\` ADD \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee'`); + await queryRunner.query(`ALTER TABLE \`profileAssessment\` ADD \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee'`); + await queryRunner.query(`ALTER TABLE \`profileCertificate\` ADD CONSTRAINT \`FK_7ae014c31077ea18d731735ec2a\` FOREIGN KEY (\`profileEmployeeId\`) REFERENCES \`profileEmployee\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`profileTraining\` ADD CONSTRAINT \`FK_888dd3a5637446912458a7e17ca\` FOREIGN KEY (\`profileEmployeeId\`) REFERENCES \`profileEmployee\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`profileInsignia\` ADD CONSTRAINT \`FK_a1652104fa8e8d9c3231bf32dfe\` FOREIGN KEY (\`profileEmployeeId\`) REFERENCES \`profileEmployee\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`profileHonor\` ADD CONSTRAINT \`FK_d5f2346dd8ccebf9a26178ed9b3\` FOREIGN KEY (\`profileEmployeeId\`) REFERENCES \`profileEmployee\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`profileAssessment\` ADD CONSTRAINT \`FK_47feb44a370ff188acb938c7bca\` FOREIGN KEY (\`profileEmployeeId\`) REFERENCES \`profileEmployee\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileAssessment\` DROP FOREIGN KEY \`FK_47feb44a370ff188acb938c7bca\``); + await queryRunner.query(`ALTER TABLE \`profileHonor\` DROP FOREIGN KEY \`FK_d5f2346dd8ccebf9a26178ed9b3\``); + await queryRunner.query(`ALTER TABLE \`profileInsignia\` DROP FOREIGN KEY \`FK_a1652104fa8e8d9c3231bf32dfe\``); + await queryRunner.query(`ALTER TABLE \`profileTraining\` DROP FOREIGN KEY \`FK_888dd3a5637446912458a7e17ca\``); + await queryRunner.query(`ALTER TABLE \`profileCertificate\` DROP FOREIGN KEY \`FK_7ae014c31077ea18d731735ec2a\``); + await queryRunner.query(`ALTER TABLE \`profileAssessment\` DROP COLUMN \`profileEmployeeId\``); + await queryRunner.query(`ALTER TABLE \`profileHonor\` DROP COLUMN \`profileEmployeeId\``); + await queryRunner.query(`ALTER TABLE \`profileInsignia\` DROP COLUMN \`profileEmployeeId\``); + await queryRunner.query(`ALTER TABLE \`profileTraining\` DROP COLUMN \`profileEmployeeId\``); + await queryRunner.query(`ALTER TABLE \`profileCertificate\` DROP COLUMN \`profileEmployeeId\``); + } + +}