From 660deeb3a4b29fdbff21dd779afb65a979c705bf Mon Sep 17 00:00:00 2001 From: Kittapath Date: Mon, 13 May 2024 17:52:55 +0700 Subject: [PATCH 1/2] migrate --- ...18469-update_table_profileemployee_add_pk3.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/migration/1715597418469-update_table_profileemployee_add_pk3.ts diff --git a/src/migration/1715597418469-update_table_profileemployee_add_pk3.ts b/src/migration/1715597418469-update_table_profileemployee_add_pk3.ts new file mode 100644 index 00000000..5e1c4c3b --- /dev/null +++ b/src/migration/1715597418469-update_table_profileemployee_add_pk3.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableProfileemployeeAddPk31715597418469 implements MigrationInterface { + name = 'UpdateTableProfileemployeeAddPk31715597418469' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileOther\` ADD \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee'`); + await queryRunner.query(`ALTER TABLE \`profileOther\` ADD CONSTRAINT \`FK_b7ef3007bce554a41bdb896ed96\` 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 \`profileOther\` DROP FOREIGN KEY \`FK_b7ef3007bce554a41bdb896ed96\``); + await queryRunner.query(`ALTER TABLE \`profileOther\` DROP COLUMN \`profileEmployeeId\``); + } + +} From 6127a594bd0de32a184e3f10ffbef762ddca2550 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 13 May 2024 17:59:11 +0700 Subject: [PATCH 2/2] rename controller --- ...sController.ts => ProfileAssessmentsEmployeeController.ts} | 4 ++-- ...eController.ts => ProfileCertificateEmployeeController.ts} | 4 ++-- ...eeHonorController.ts => ProfileHonorEmployeeController.ts} | 4 ++-- ...gniaController.ts => ProfileInsigniaEmployeeController.ts} | 4 ++-- ...ningController.ts => ProfileTrainingEmployeeController.ts} | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) rename src/controllers/{ProfileEmployeeAssessmentsController.ts => ProfileAssessmentsEmployeeController.ts} (98%) rename src/controllers/{ProfileEmployeeCertificateController.ts => ProfileCertificateEmployeeController.ts} (97%) rename src/controllers/{ProfileEmployeeHonorController.ts => ProfileHonorEmployeeController.ts} (97%) rename src/controllers/{ProfileEmployeeInsigniaController.ts => ProfileInsigniaEmployeeController.ts} (98%) rename src/controllers/{ProfileEmployeeTrainingController.ts => ProfileTrainingEmployeeController.ts} (97%) diff --git a/src/controllers/ProfileEmployeeAssessmentsController.ts b/src/controllers/ProfileAssessmentsEmployeeController.ts similarity index 98% rename from src/controllers/ProfileEmployeeAssessmentsController.ts rename to src/controllers/ProfileAssessmentsEmployeeController.ts index 3862b106..4f65867d 100644 --- a/src/controllers/ProfileEmployeeAssessmentsController.ts +++ b/src/controllers/ProfileAssessmentsEmployeeController.ts @@ -33,7 +33,7 @@ import { RequestWithUser } from "../middlewares/user"; @Route("api/v1/org/profile-employee/assessments") @Tags("ProfileEmployeeAssessments") @Security("bearerAuth") -export class ProfileEmployeeAssessmentsController extends Controller { +export class ProfileAssessmentsEmployeeController extends Controller { private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee); private profileAssessmentsRepository = AppDataSource.getRepository(ProfileAssessment); private profileAssessmentsHistoryRepository = @@ -188,7 +188,7 @@ export class ProfileEmployeeAssessmentsController extends Controller { const result = await this.profileAssessmentsRepository.delete({ id: assessmentId }); - if (result.affected && result.affected <= 0) + if (result.affected == undefined || result.affected <= 0) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); return new HttpSuccess(); diff --git a/src/controllers/ProfileEmployeeCertificateController.ts b/src/controllers/ProfileCertificateEmployeeController.ts similarity index 97% rename from src/controllers/ProfileEmployeeCertificateController.ts rename to src/controllers/ProfileCertificateEmployeeController.ts index 03d05af9..255d38af 100644 --- a/src/controllers/ProfileEmployeeCertificateController.ts +++ b/src/controllers/ProfileCertificateEmployeeController.ts @@ -28,7 +28,7 @@ import { ProfileEmployee } from "../entities/ProfileEmployee"; @Route("api/v1/org/profile-employee/certificate") @Tags("ProfileEmployeeCertificate") @Security("bearerAuth") -export class ProfileEmployeeCertificateController extends Controller { +export class ProfileCertificateEmployeeController extends Controller { private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee); private certificateRepo = AppDataSource.getRepository(ProfileCertificate); private certificateHistoryRepo = AppDataSource.getRepository(ProfileCertificateHistory); @@ -171,7 +171,7 @@ export class ProfileEmployeeCertificateController extends Controller { id: certificateId, }); - if (certificateResult.affected && certificateResult.affected <= 0) { + if (certificateResult.affected == undefined || certificateResult.affected <= 0) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } diff --git a/src/controllers/ProfileEmployeeHonorController.ts b/src/controllers/ProfileHonorEmployeeController.ts similarity index 97% rename from src/controllers/ProfileEmployeeHonorController.ts rename to src/controllers/ProfileHonorEmployeeController.ts index 77728751..44157de8 100644 --- a/src/controllers/ProfileEmployeeHonorController.ts +++ b/src/controllers/ProfileHonorEmployeeController.ts @@ -24,7 +24,7 @@ import { ProfileEmployee } from "../entities/ProfileEmployee"; @Route("api/v1/org/profile-employee/honor") @Tags("ProfileEmployeeHonor") @Security("bearerAuth") -export class ProfileEmployeeHonorController extends Controller { +export class ProfileHonorEmployeeController extends Controller { private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee); private honorRepo = AppDataSource.getRepository(ProfileHonor); private honorHistoryRepo = AppDataSource.getRepository(ProfileHonorHistory); @@ -162,7 +162,7 @@ export class ProfileEmployeeHonorController extends Controller { const result = await this.honorRepo.delete({ id: honorId }); - if (result.affected && result.affected <= 0) { + if (result.affected == undefined || result.affected <= 0) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } diff --git a/src/controllers/ProfileEmployeeInsigniaController.ts b/src/controllers/ProfileInsigniaEmployeeController.ts similarity index 98% rename from src/controllers/ProfileEmployeeInsigniaController.ts rename to src/controllers/ProfileInsigniaEmployeeController.ts index c4340606..4089c8a1 100644 --- a/src/controllers/ProfileEmployeeInsigniaController.ts +++ b/src/controllers/ProfileInsigniaEmployeeController.ts @@ -29,7 +29,7 @@ import { Insignia } from "../entities/Insignia"; @Route("api/v1/org/profile-employee/insignia") @Tags("ProfileEmployeeInsignia") @Security("bearerAuth") -export class ProfileEmployeeInsigniaController extends Controller { +export class ProfileInsigniaEmployeeController extends Controller { private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee); private insigniaRepo = AppDataSource.getRepository(ProfileInsignia); private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory); @@ -220,7 +220,7 @@ export class ProfileEmployeeInsigniaController extends Controller { const result = await this.insigniaRepo.delete({ id: insigniaId }); - if (result.affected && result.affected <= 0) { + if (result.affected == undefined || result.affected <= 0) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } diff --git a/src/controllers/ProfileEmployeeTrainingController.ts b/src/controllers/ProfileTrainingEmployeeController.ts similarity index 97% rename from src/controllers/ProfileEmployeeTrainingController.ts rename to src/controllers/ProfileTrainingEmployeeController.ts index 662e0708..8e8c76d4 100644 --- a/src/controllers/ProfileEmployeeTrainingController.ts +++ b/src/controllers/ProfileTrainingEmployeeController.ts @@ -28,7 +28,7 @@ import { ProfileEmployee } from "../entities/ProfileEmployee"; @Route("api/v1/org/profile-employee/training") @Tags("ProfileEmployeeTraining") @Security("bearerAuth") -export class ProfileEmployeeTrainingController extends Controller { +export class ProfileTrainingEmployeeController extends Controller { private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee); private trainingRepo = AppDataSource.getRepository(ProfileTraining); private trainingHistoryRepo = AppDataSource.getRepository(ProfileTrainingHistory); @@ -184,7 +184,7 @@ export class ProfileEmployeeTrainingController extends Controller { const result = await this.trainingRepo.delete({ id: trainingId }); - if (result.affected && result.affected <= 0) { + if (result.affected == undefined || result.affected <= 0) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); }