From f32debfbb6a22e4a8af96044d3a1383427e43f60 Mon Sep 17 00:00:00 2001 From: Adisak Date: Mon, 3 Nov 2025 10:48:04 +0700 Subject: [PATCH 1/7] test commit --- src/controllers/OrganizationController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 142d8033..909614d5 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -1338,7 +1338,7 @@ export class OrganizationController extends Controller { .getMany() : []; - // const formattedData = orgRootData.map((orgRoot) => { + // const formattedData = orgRootData.map((orgRoot) => { //return fix const formattedData = await Promise.all( orgRootData.map(async (orgRoot) => { return { From 39a1a3bbb09631a6cc97f78f0e178ac31de2eb08 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang <153157069+AdisakKanthawilang@users.noreply.github.com> Date: Mon, 3 Nov 2025 11:56:26 +0700 Subject: [PATCH 2/7] #1767 (#205) --- src/controllers/OrganizationController.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 909614d5..89ec4400 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -1218,6 +1218,7 @@ export class OrganizationController extends Controller { "orgRoot.SECTION_CODE", "orgRoot.JOB_CODE", "orgRoot.responsibility", + "orgRoot.ancestorDNA", ]) .orderBy("orgRoot.orgRootOrder", "ASC") .getMany(); @@ -1246,6 +1247,7 @@ export class OrganizationController extends Controller { "orgChild1.SECTION_CODE", "orgChild1.JOB_CODE", "orgChild1.responsibility", + "orgChild1.ancestorDNA", ]) .orderBy("orgChild1.orgChild1Order", "ASC") .getMany() @@ -1275,6 +1277,7 @@ export class OrganizationController extends Controller { "orgChild2.JOB_CODE", "orgChild2.orgChild1Id", "orgChild2.responsibility", + "orgChild2.ancestorDNA", ]) .orderBy("orgChild2.orgChild2Order", "ASC") .getMany() @@ -1304,6 +1307,7 @@ export class OrganizationController extends Controller { "orgChild3.JOB_CODE", "orgChild3.orgChild2Id", "orgChild3.responsibility", + "orgChild3.ancestorDNA", ]) .orderBy("orgChild3.orgChild3Order", "ASC") .getMany() @@ -1333,12 +1337,13 @@ export class OrganizationController extends Controller { "orgChild4.JOB_CODE", "orgChild4.orgChild3Id", "orgChild4.responsibility", + "orgChild4.ancestorDNA", ]) .orderBy("orgChild4.orgChild4Order", "ASC") .getMany() : []; - // const formattedData = orgRootData.map((orgRoot) => { //return fix + // const formattedData = orgRootData.map((orgRoot) => { const formattedData = await Promise.all( orgRootData.map(async (orgRoot) => { return { @@ -1351,6 +1356,7 @@ export class OrganizationController extends Controller { orgCode: orgRoot.orgRootCode + "00", orgTreeRank: orgRoot.orgRootRank, orgTreeRankSub: orgRoot.orgRootRankSub, + orgRootDnaId: orgRoot.ancestorDNA, DEPARTMENT_CODE: orgRoot.DEPARTMENT_CODE, DIVISION_CODE: orgRoot.DIVISION_CODE, SECTION_CODE: orgRoot.SECTION_CODE, @@ -1466,6 +1472,8 @@ export class OrganizationController extends Controller { orgCode: orgRoot.orgRootCode + orgChild1.orgChild1Code, orgTreeRank: orgChild1.orgChild1Rank, orgTreeRankSub: orgChild1.orgChild1RankSub, + orgRootDnaId: orgRoot.ancestorDNA, + orgChild1DnaId: orgChild1.ancestorDNA, DEPARTMENT_CODE: orgChild1.DEPARTMENT_CODE, DIVISION_CODE: orgChild1.DIVISION_CODE, SECTION_CODE: orgChild1.SECTION_CODE, @@ -1587,6 +1595,9 @@ export class OrganizationController extends Controller { orgCode: orgRoot.orgRootCode + orgChild2.orgChild2Code, orgTreeRank: orgChild2.orgChild2Rank, orgTreeRankSub: orgChild2.orgChild2RankSub, + orgRootDnaId: orgRoot.ancestorDNA, + orgChild1DnaId: orgChild1.ancestorDNA, + orgChild2DnaId: orgChild2.ancestorDNA, DEPARTMENT_CODE: orgChild2.DEPARTMENT_CODE, DIVISION_CODE: orgChild2.DIVISION_CODE, SECTION_CODE: orgChild2.SECTION_CODE, @@ -1709,6 +1720,10 @@ export class OrganizationController extends Controller { orgCode: orgRoot.orgRootCode + orgChild3.orgChild3Code, orgTreeRank: orgChild3.orgChild3Rank, orgTreeRankSub: orgChild3.orgChild3RankSub, + orgRootDnaId: orgRoot.ancestorDNA, + orgChild1DnaId: orgChild1.ancestorDNA, + orgChild2DnaId: orgChild2.ancestorDNA, + orgChild3DnaId: orgChild3.ancestorDNA, DEPARTMENT_CODE: orgChild3.DEPARTMENT_CODE, DIVISION_CODE: orgChild3.DIVISION_CODE, SECTION_CODE: orgChild3.SECTION_CODE, @@ -1831,6 +1846,11 @@ export class OrganizationController extends Controller { orgCode: orgRoot.orgRootCode + orgChild4.orgChild4Code, orgTreeRank: orgChild4.orgChild4Rank, orgTreeRankSub: orgChild4.orgChild4RankSub, + orgRootDnaId: orgRoot.ancestorDNA, + orgChild1DnaId: orgChild1.ancestorDNA, + orgChild2DnaId: orgChild2.ancestorDNA, + orgChild3DnaId: orgChild3.ancestorDNA, + orgChild4DnaId: orgChild4.ancestorDNA, DEPARTMENT_CODE: orgChild4.DEPARTMENT_CODE, DIVISION_CODE: orgChild4.DIVISION_CODE, SECTION_CODE: orgChild4.SECTION_CODE, From dcff08db6f83a916accb07cc7d72cf0809259ee9 Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Mon, 3 Nov 2025 14:51:42 +0700 Subject: [PATCH 3/7] update Retire Clear Org --- src/controllers/ImportDataController.ts | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index 08eacd6c..d6345ac0 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -6312,4 +6312,50 @@ export class ImportDataController extends Controller { } return new HttpSuccess(); } + + @Post("updateRetireClearOrg") + async updateRetireClearOrg(@Request() request: { user: Record }) { + const profiles = await this.profileRepo.find({ + where: { + isLeave: true, + }, + }); + + for (const item of profiles) { + const posmaster = await this.posMasterRepo.findOne({ + where: { + orgRevision: { + orgRevisionIsCurrent: false, + orgRevisionIsDraft: true, + }, + next_holderId: item.id, + }, + }); + if (!posmaster) continue; + posmaster.next_holderId = null; + await this.posMasterRepo.save(posmaster); + } + + const profileEmps = await this.profileEmpRepo.find({ + where: { + isLeave: true, + }, + }); + + for (const item of profileEmps) { + const posmaster = await this.posMasterEmpRepo.findOne({ + where: { + orgRevision: { + orgRevisionIsCurrent: false, + orgRevisionIsDraft: true, + }, + next_holderId: item.id, + }, + }); + if (!posmaster) continue; + posmaster.next_holderId = null; + await this.posMasterEmpRepo.save(posmaster); + } + return new HttpSuccess(); + } } From 19d665fd69882c95b6cfcaa3de16c75665cbf9bb Mon Sep 17 00:00:00 2001 From: Adisak Date: Mon, 3 Nov 2025 15:57:41 +0700 Subject: [PATCH 4/7] migration --- src/entities/ApiKey.ts | 2 +- src/entities/ProfileTraining.ts | 4 ++-- .../1762159481993-update_size_keyapi_field.ts | 17 +++++++++++++++++ .../1762159824907-update_size_place_field.ts | 16 ++++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 src/migration/1762159481993-update_size_keyapi_field.ts create mode 100644 src/migration/1762159824907-update_size_place_field.ts diff --git a/src/entities/ApiKey.ts b/src/entities/ApiKey.ts index 8f220fea..c8e099e8 100644 --- a/src/entities/ApiKey.ts +++ b/src/entities/ApiKey.ts @@ -14,9 +14,9 @@ export class ApiKey extends EntityBase { name: string; @Column({ + type: 'longtext', nullable: true, comment: "keyApi", - length: 255, default: null, }) keyApi: string; diff --git a/src/entities/ProfileTraining.ts b/src/entities/ProfileTraining.ts index e4b29b70..2afaa17a 100644 --- a/src/entities/ProfileTraining.ts +++ b/src/entities/ProfileTraining.ts @@ -55,9 +55,9 @@ export class ProfileTraining extends EntityBase { topic: string; @Column({ + type: 'longtext', nullable: true, - length: 200, - comment: "สถานที่ฝึกอบรม/ดูงาน ", + comment: "สถานที่ฝึกอบรม/ดูงาน", default: null, }) place: string; diff --git a/src/migration/1762159481993-update_size_keyapi_field.ts b/src/migration/1762159481993-update_size_keyapi_field.ts new file mode 100644 index 00000000..17b1b0d2 --- /dev/null +++ b/src/migration/1762159481993-update_size_keyapi_field.ts @@ -0,0 +1,17 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateSizeKeyapiField1762159481993 implements MigrationInterface { + name = 'UpdateSizeKeyapiField1762159481993' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`apiKey\` DROP COLUMN \`keyApi\``); + await queryRunner.query(`ALTER TABLE \`apiKey\` ADD \`keyApi\` longtext NULL COMMENT 'keyApi'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`apiKey\` DROP COLUMN \`keyApi\``); + await queryRunner.query(`ALTER TABLE \`apiKey\` ADD \`keyApi\` varchar(255) NULL COMMENT 'keyApi'`); + + } + +} diff --git a/src/migration/1762159824907-update_size_place_field.ts b/src/migration/1762159824907-update_size_place_field.ts new file mode 100644 index 00000000..56976d9f --- /dev/null +++ b/src/migration/1762159824907-update_size_place_field.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateSizePlaceField1762159824907 implements MigrationInterface { + name = 'UpdateSizePlaceField1762159824907' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileTraining\` DROP COLUMN \`place\``); + await queryRunner.query(`ALTER TABLE \`profileTraining\` ADD \`place\` longtext NULL COMMENT 'สถานที่ฝึกอบรม/ดูงาน'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileTraining\` DROP COLUMN \`place\``); + await queryRunner.query(`ALTER TABLE \`profileTraining\` ADD \`place\` varchar(200) NULL COMMENT 'สถานที่ฝึกอบรม/ดูงาน '`); + } + +} From 3e6ee5d8689e09ae6855a133af6f1c39b3035e4c Mon Sep 17 00:00:00 2001 From: Adisak Date: Mon, 3 Nov 2025 17:35:15 +0700 Subject: [PATCH 5/7] migration --- src/entities/AuthRole.ts | 7 +++++++ ...863-add_field_isAdminVisibled_table_AuthRole.ts | 14 ++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/migration/1762165716863-add_field_isAdminVisibled_table_AuthRole.ts diff --git a/src/entities/AuthRole.ts b/src/entities/AuthRole.ts index 3dbd29ea..5fcfd9ae 100644 --- a/src/entities/AuthRole.ts +++ b/src/entities/AuthRole.ts @@ -23,6 +23,13 @@ export class AuthRole extends EntityBase { }) roleDescription: string; + @Column({ + nullable: true, + comment: "ข้อมูลที่ role admin สามารถเห็นได้", + default: null, + }) + isAdminVisibled: boolean; + @OneToMany(() => AuthRoleAttr, (authRoleAttr) => authRoleAttr.authRoleAttrForRole) authRoles: AuthRoleAttr[]; diff --git a/src/migration/1762165716863-add_field_isAdminVisibled_table_AuthRole.ts b/src/migration/1762165716863-add_field_isAdminVisibled_table_AuthRole.ts new file mode 100644 index 00000000..42348da7 --- /dev/null +++ b/src/migration/1762165716863-add_field_isAdminVisibled_table_AuthRole.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddFieldIsAdminVisibledTableAuthRole1762165716863 implements MigrationInterface { + name = 'AddFieldIsAdminVisibledTableAuthRole1762165716863' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`authRole\` ADD \`isAdminVisibled\` tinyint NULL COMMENT 'ข้อมูลที่ role admin สามารถเห็นได้'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`authRole\` DROP COLUMN \`isAdminVisibled\``); + } + +} From ee4bff7f50b48e004623eea163376919f72d730d Mon Sep 17 00:00:00 2001 From: harid Date: Mon, 3 Nov 2025 18:05:29 +0700 Subject: [PATCH 6/7] =?UTF-8?q?fix=20=E0=B8=9C=E0=B8=B9=E0=B9=89=E0=B9=80?= =?UTF-8?q?=E0=B8=81=E0=B8=A9=E0=B8=B5=E0=B8=A2=E0=B8=93=20=E0=B9=83?= =?UTF-8?q?=E0=B8=99=E0=B9=81=E0=B8=9A=E0=B8=9A=E0=B8=A3=E0=B9=88=E0=B8=B2?= =?UTF-8?q?=E0=B8=87=20=E0=B8=82=E0=B8=AD=E0=B8=87=E0=B8=A3=E0=B8=B0?= =?UTF-8?q?=E0=B8=9A=E0=B8=9A=E0=B9=82=E0=B8=84=E0=B8=A3=E0=B8=87=E0=B8=AA?= =?UTF-8?q?=E0=B8=A3=E0=B9=89=E0=B8=B2=E0=B8=87=E0=B9=84=E0=B8=A1=E0=B9=88?= =?UTF-8?q?=E0=B8=96=E0=B8=B9=E0=B8=81=E0=B8=9B=E0=B8=A5=E0=B8=94=20#1912?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.ts | 4 +- src/controllers/CommandController.ts | 94 ++++++++++++++++------------ 2 files changed, 55 insertions(+), 43 deletions(-) diff --git a/src/app.ts b/src/app.ts index 6913a2c1..368be40f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -67,8 +67,8 @@ async function main() { }); // const cronTime_Oct = "0 0 1 10 *"; - // Test #1892 - const cronTime_Oct = "0 0 31 10 *"; + // Test #1912 + const cronTime_Oct = "0 0 4 11 *"; cron.schedule(cronTime_Oct, async () => { try { const commandController = new CommandController(); diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index a6885004..e4538538 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -1477,24 +1477,6 @@ export class CommandController extends Controller { } // @Get("XXX") async cronjobUpdateRetirementStatus(/*@Request() request: RequestWithUser*/) { - // let body = { - // client_id: "gettoken", - // client_secret: process.env.AUTH_ACCOUNT_SECRET, - // grant_type: "client_credentials", - // }; - // const postData = querystring.stringify(body); - // const response = await axios.post( - // `${process.env.KC_URL}/realms/${process.env.KC_REALMS}/protocol/openid-connect/token`, - // postData, - // { - // headers: { - // "Content-Type": "application/x-www-form-urlencoded", - // api_key: process.env.API_KEY, - // }, - // }, - // ); - // const adminToken = response.data.access_token; - // const adminToken = request.headers["authorization"]?.replace("Bearer ", ""); const adminToken = await getToken() ?? ""; const today = new Date(); today.setUTCHours(0, 0, 0, 0); @@ -1668,32 +1650,30 @@ export class CommandController extends Controller { } async posMasterRetire(profileId: string, type: string, _Date: Date) { - const orgRevision = await this.orgRevisionRepo.findOne({ + const revisionIsCurrent = await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, }); - if (orgRevision) { + if (revisionIsCurrent) { let _posMaster: any = null; - let _position: any = null; if (type == "OFFICER") { _posMaster = await this.posMasterRepository.findOne({ where: { - orgRevisionId: orgRevision.id, + orgRevisionId: revisionIsCurrent.id, current_holderId: profileId, }, }); if (_posMaster) { - _position = await this.positionRepository.findOne({ - where: { + await this.positionRepository.update( + { posMasterId: _posMaster.id, positionIsSelected: true, }, - }); - if (_position) { - _position.positionIsSelected = false; - _position.lastUpdateFullName = "System Administrator"; - _position.lastUpdatedAt = _Date; - await this.positionRepository.save(_position); - } + { + positionIsSelected: false, + lastUpdateFullName: "System Administrator", + lastUpdatedAt: _Date, + } + ); _posMaster.isSit = false; _posMaster.current_holderId = null; _posMaster.lastUpdateFullName = "System Administrator"; @@ -1701,26 +1681,57 @@ export class CommandController extends Controller { await this.posMasterRepository.save(_posMaster); await CreatePosMasterHistoryOfficer(_posMaster.id, null); } + const revisionIsDraft = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: false, orgRevisionIsDraft: true }, + }); + if (revisionIsDraft) { + _posMaster = null; + _posMaster = await this.posMasterRepository.findOne({ + where: { + orgRevisionId: revisionIsDraft.id, + next_holderId: profileId, + }, + }); + if (_posMaster) { + await this.positionRepository.update( + { + posMasterId: _posMaster.id, + positionIsSelected: true, + }, + { + positionIsSelected: false, + lastUpdateFullName: "System Administrator", + lastUpdatedAt: _Date, + } + ); + _posMaster.isSit = false; + _posMaster.next_holderId = null; + _posMaster.lastUpdateFullName = "System Administrator"; + _posMaster.lastUpdatedAt = _Date; + await this.posMasterRepository.save(_posMaster); + await CreatePosMasterHistoryOfficer(_posMaster.id, null); + } + // console.log("clear posMaster & position 'Draf' success") + } } else if (type == "EMPLOYEE") { _posMaster = await this.employeePosMasterRepository.findOne({ where: { - orgRevisionId: orgRevision.id, + orgRevisionId: revisionIsCurrent.id, current_holderId: profileId, }, }); if (_posMaster) { - _position = await this.employeePositionRepository.findOne({ - where: { + await this.employeePositionRepository.update( + { posMasterId: _posMaster.id, positionIsSelected: true, }, - }); - if (_position) { - _position.positionIsSelected = false; - _position.lastUpdateFullName = "System Administrator"; - _position.lastUpdatedAt = _Date; - await this.employeePositionRepository.save(_position); - } + { + positionIsSelected: false, + lastUpdateFullName: "System Administrator", + lastUpdatedAt: _Date, + } + ); _posMaster.isSit = false; _posMaster.current_holderId = null; _posMaster.lastUpdateFullName = "System Administrator"; @@ -1729,6 +1740,7 @@ export class CommandController extends Controller { await CreatePosMasterHistoryEmployee(_posMaster.id, null); } } + // console.log("clear posMaster & position 'Current' success") } } From 40bc95bb87e613d2f8a1b71971d591f22d754cb6 Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Mon, 3 Nov 2025 21:37:50 +0700 Subject: [PATCH 7/7] update org --- src/controllers/ImportDataController.ts | 44 ++++++++++++++----------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index d6345ac0..e2339b8f 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -6316,45 +6316,49 @@ export class ImportDataController extends Controller { @Post("updateRetireClearOrg") async updateRetireClearOrg(@Request() request: { user: Record }) { const profiles = await this.profileRepo.find({ - where: { - isLeave: true, - }, + where: { isLeave: true }, + select: ["id"], }); - - for (const item of profiles) { - const posmaster = await this.posMasterRepo.findOne({ + const profileIds = profiles.map((p) => p.id); + if (profileIds.length > 0) { + const posmasters = await this.posMasterRepo.find({ where: { orgRevision: { orgRevisionIsCurrent: false, orgRevisionIsDraft: true, }, - next_holderId: item.id, + next_holderId: In(profileIds), }, }); - if (!posmaster) continue; - posmaster.next_holderId = null; - await this.posMasterRepo.save(posmaster); + for (const posmaster of posmasters) { + posmaster.next_holderId = null; + } + if (posmasters.length > 0) { + await this.posMasterRepo.save(posmasters); + } } const profileEmps = await this.profileEmpRepo.find({ - where: { - isLeave: true, - }, + where: { isLeave: true }, + select: ["id"], }); - - for (const item of profileEmps) { - const posmaster = await this.posMasterEmpRepo.findOne({ + const profileEmpIds = profileEmps.map((p) => p.id); + if (profileEmpIds.length > 0) { + const posmasterEmps = await this.posMasterEmpRepo.find({ where: { orgRevision: { orgRevisionIsCurrent: false, orgRevisionIsDraft: true, }, - next_holderId: item.id, + next_holderId: In(profileEmpIds), }, }); - if (!posmaster) continue; - posmaster.next_holderId = null; - await this.posMasterEmpRepo.save(posmaster); + for (const posmasterEmp of posmasterEmps) { + posmasterEmp.next_holderId = null; + } + if (posmasterEmps.length > 0) { + await this.posMasterEmpRepo.save(posmasterEmps); + } } return new HttpSuccess(); }