From eb1264b8851196576749ba48caea7ef49d9f7d23 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 19 Dec 2024 10:31:21 +0700 Subject: [PATCH 1/4] #857 (4),(5) --- .../DevelopmentEmployeeHistoryController.ts | 35 +++++++++++++------ .../DevelopmentHistoryController.ts | 16 ++++++--- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 45a4970..65dadc1 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -327,15 +327,17 @@ export class DevelopmentEmployeeHistoryController extends Controller { const formattedData = development.map((item) => ({ id: item.id, citizenId: item.citizenId, - fullName: item.prefix != null && item.firstName != null && item.lastName != null - ? `${item?.prefix}${item?.firstName} ${item?.lastName}` - : "", + fullName: + item.prefix != null && item.firstName != null && item.lastName != null + ? `${item?.prefix}${item?.firstName} ${item?.lastName}` + : "", position: item.position, year: item.development.year, posType: item.employeePosType ? item.employeePosType.posTypeName : null, - posLevel: item.employeePosType && item.employeePosLevel - ? `${item.employeePosType.posTypeShortName} ${item.employeePosLevel.posLevelName}` - : null, + posLevel: + item.employeePosType && item.employeePosLevel + ? `${item.employeePosType.posTypeShortName} ${item.employeePosLevel.posLevelName}` + : null, projectName: item.development.projectName, })); @@ -355,7 +357,12 @@ export class DevelopmentEmployeeHistoryController extends Controller { if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_HISTORY_EMP"); const type = "EMPLOYEE"; const getDevelopment = await this.developmentHistoryRepository.findOne({ - relations: ["development", "employeePosLevel", "employeePosType"], + relations: [ + "development", + "development.developmentOthers", + "employeePosLevel", + "employeePosType", + ], where: { id: id, type: type }, }); if (!getDevelopment) { @@ -389,14 +396,20 @@ export class DevelopmentEmployeeHistoryController extends Controller { dateStart: getDevelopment.development != null ? getDevelopment.development.dateStart : null, dateEnd: getDevelopment.development != null ? getDevelopment.development.dateEnd : null, totalDate: getDevelopment.development != null ? getDevelopment.development.totalDate : null, - addressAcademic: - getDevelopment.development != null ? getDevelopment.development.addressAcademic : null, - topicAcademic: - getDevelopment.development != null ? getDevelopment.development.topicAcademic : null, + // addressAcademic: + // getDevelopment.development != null ? getDevelopment.development.addressAcademic : null, + // topicAcademic: + // getDevelopment.development != null ? getDevelopment.development.topicAcademic : null, dateStudyStart: getDevelopment.development != null ? getDevelopment.development.dateStudyStart : null, dateStudyEnd: getDevelopment.development != null ? getDevelopment.development.dateStudyEnd : null, + academic: getDevelopment.development?.developmentOthers + ? getDevelopment.development.developmentOthers.map((dev) => ({ + topicAcademic: dev.topicAcademic, + addressAcademic: dev.addressAcademic, + })) + : [], }; return new HttpSuccess(formattedData); diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index c8928c9..368858f 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -350,7 +350,7 @@ export class DevelopmentOfficerHistoryController extends Controller { await new permission().PermissionGet(request, "SYS_DEV_HISTORY_OFFICER"); const type = "OFFICER"; const getDevelopment = await this.developmentHistoryRepository.findOne({ - relations: ["development", "posLevel", "posType"], + relations: ["development", "development.developmentOthers","posLevel", "posType"], where: { id: id, type: type }, }); if (!getDevelopment) { @@ -381,14 +381,20 @@ export class DevelopmentOfficerHistoryController extends Controller { dateStart: getDevelopment.development != null ? getDevelopment.development.dateStart : null, dateEnd: getDevelopment.development != null ? getDevelopment.development.dateEnd : null, totalDate: getDevelopment.development != null ? getDevelopment.development.totalDate : null, - addressAcademic: - getDevelopment.development != null ? getDevelopment.development.addressAcademic : null, - topicAcademic: - getDevelopment.development != null ? getDevelopment.development.topicAcademic : null, + // addressAcademic: + // getDevelopment.development != null ? getDevelopment.development.addressAcademic : null, + // topicAcademic: + // getDevelopment.development != null ? getDevelopment.development.topicAcademic : null, dateStudyStart: getDevelopment.development != null ? getDevelopment.development.dateStudyStart : null, dateStudyEnd: getDevelopment.development != null ? getDevelopment.development.dateStudyEnd : null, + academic: getDevelopment.development?.developmentOthers + ? getDevelopment.development.developmentOthers.map(dev => ({ + topicAcademic: dev.topicAcademic, + addressAcademic: dev.addressAcademic + })) + : [] }; return new HttpSuccess(formattedData); From 48dcb3582a2e30c23c91865a851bed8e0e5173f2 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 19 Dec 2024 11:14:57 +0700 Subject: [PATCH 2/4] add relation --- src/entities/DevelopmentOther.ts | 4 ++++ src/entities/Province.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/entities/DevelopmentOther.ts b/src/entities/DevelopmentOther.ts index 4315669..0e627f0 100644 --- a/src/entities/DevelopmentOther.ts +++ b/src/entities/DevelopmentOther.ts @@ -36,6 +36,10 @@ export class DevelopmentOther extends EntityBase { @ManyToOne(() => Development, (development: Development) => development.developmentOthers) @JoinColumn({ name: "developmentId" }) development: Development; + + @ManyToOne(() => Province, (province: Province) => province.developmentOthers) + @JoinColumn({ name: "developmentId" }) + province: Province; } export class UpdateDevelopmentOther { diff --git a/src/entities/Province.ts b/src/entities/Province.ts index a826b67..f697b97 100644 --- a/src/entities/Province.ts +++ b/src/entities/Province.ts @@ -2,6 +2,7 @@ import { Entity, Column, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { Development } from "./Development"; import { DevelopmentAddress } from "./DevelopmentAddress"; +import { DevelopmentOther } from "./DevelopmentOther"; @Entity("province") export class Province extends EntityBase { @@ -21,6 +22,9 @@ export class Province extends EntityBase { @OneToMany(() => Development, (development: Development) => development.provinceActual) developmentActuals: Development[]; + + @OneToMany(() => DevelopmentOther, (developmentOther: DevelopmentOther) => developmentOther.province) + developmentOthers: Development[]; } export class CreateProvince { From c0e38237a6dfbbc7cd109792ecc31df48790d269 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 19 Dec 2024 11:41:06 +0700 Subject: [PATCH 3/4] api clear db --- src/controllers/DevelopmentController.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index b131536..2364ddc 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -91,6 +91,17 @@ export class DevelopmentController extends Controller { private strategyChild4Repository = AppDataSource.getRepository(StrategyChild4); private strategyChild5Repository = AppDataSource.getRepository(StrategyChild5); + /** + * API ล้างข้อมูล + * + * @summary ล้างข้อมูล + * + */ + @Get("clear-db") + async ClearDb() { + return new HttpSuccess(); + } + /** * API เพิ่มโครงการ/หลักสูตรการฝึกอบรม * From a648fb3f243d998d66c9408fc2764b48a40c0ae5 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 19 Dec 2024 11:45:31 +0700 Subject: [PATCH 4/4] migrate --- ...427091-update_devorder_add_relation_province.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/migration/1734583427091-update_devorder_add_relation_province.ts diff --git a/src/migration/1734583427091-update_devorder_add_relation_province.ts b/src/migration/1734583427091-update_devorder_add_relation_province.ts new file mode 100644 index 0000000..9084218 --- /dev/null +++ b/src/migration/1734583427091-update_devorder_add_relation_province.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateDevorderAddRelationProvince1734583427091 implements MigrationInterface { + name = 'UpdateDevorderAddRelationProvince1734583427091' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD CONSTRAINT \`FK_d5dfdb7ca0d11c0cdf3b3a55e6f\` FOREIGN KEY (\`developmentId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP FOREIGN KEY \`FK_d5dfdb7ca0d11c0cdf3b3a55e6f\``); + } + +}