From 6b719049b09ead7b541b09db57728d08926c7157 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 2 Oct 2025 11:40:01 +0700 Subject: [PATCH] =?UTF-8?q?update=20script=20=E0=B8=A3=E0=B8=B1=E0=B8=99?= =?UTF-8?q?=E0=B9=80=E0=B8=81=E0=B8=A9=E0=B8=B5=E0=B8=A2=E0=B8=93=20#169?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 13 +++++++--- .../ProfileGovernmentController.ts | 16 +++++++++---- .../ProfileGovernmentEmployeeController.ts | 24 ++++++++++++------- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 2f72f709..68bd0588 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -1478,7 +1478,7 @@ export class CommandController extends Controller { return new HttpSuccess(); } - async cronjobUpdateRetirementStatus() { + async cronjobUpdateRetirementStatus(/*@Request() request: RequestWithUser*/) { let body = { client_id: "gettoken", client_secret: process.env.AUTH_ACCOUNT_SECRET, @@ -1576,7 +1576,7 @@ export class CommandController extends Controller { } // let profiles: ProfileEmployee[] = []; await Promise.all( - response_.data.result.map(async (x: any) => { + response_.data.result.profiles.map(async (x: any) => { const _profileEmp = await this.profileEmployeeRepository.findOneBy({ id: x.profileId }); if (_profileEmp) { // บันทึกลงประวัติตำแหน่ง @@ -1625,7 +1625,6 @@ export class CommandController extends Controller { amount: null, positionSalaryAmount: null, mouthSalaryAmount: null, - profileId: profileId, posNo: null, positionExecutive: null, positionType: null, @@ -1655,6 +1654,14 @@ export class CommandController extends Controller { const history = new ProfileSalaryHistory(); Object.assign(history, { ...data, id: undefined }); data.dateGovernment = _Date; + if (type == "OFFICER") { + data.profileId = profileId; + data.profileEmployeeId = null; + } + else if (type == "EMPLOYEE"){ + data.profileEmployeeId = profileId; + data.profileId = null; + } const savedData = await this.salaryRepo.save(data); history.profileSalaryId = savedData.id; await this.salaryHistoryRepo.save(history); diff --git a/src/controllers/ProfileGovernmentController.ts b/src/controllers/ProfileGovernmentController.ts index 8abe6617..f2acbaba 100644 --- a/src/controllers/ProfileGovernmentController.ts +++ b/src/controllers/ProfileGovernmentController.ts @@ -249,9 +249,13 @@ export class ProfileGovernmentHistoryController extends Controller { if (record.leaveType == "RETIRE") { _profileSalary = record?.profileSalary.length > 1 ? record?.profileSalary[1] - : null; + : record?.profileSalary.length > 0 + ? record?.profileSalary[0] + : null; } else { - _profileSalary = record?.profileSalary[0]; + _profileSalary = record?.profileSalary.length > 0 + ? record?.profileSalary[0] + : null; } if (_profileSalary) { _OrgLeave = [ @@ -404,9 +408,13 @@ export class ProfileGovernmentHistoryController extends Controller { if (record.leaveType == "RETIRE") { _profileSalary = record?.profileSalary.length > 1 ? record?.profileSalary[1] - : null; + : record?.profileSalary.length > 0 + ? record?.profileSalary[0] + : null; } else { - _profileSalary = record?.profileSalary[0]; + _profileSalary = record?.profileSalary.length > 0 + ? record?.profileSalary[0] + : null; } if (_profileSalary) { _OrgLeave = [ diff --git a/src/controllers/ProfileGovernmentEmployeeController.ts b/src/controllers/ProfileGovernmentEmployeeController.ts index 9191eb2e..ce170d17 100644 --- a/src/controllers/ProfileGovernmentEmployeeController.ts +++ b/src/controllers/ProfileGovernmentEmployeeController.ts @@ -264,11 +264,15 @@ export class ProfileGovernmentEmployeeController extends Controller { // profileSalary.length > 0 && profileSalary[0].orgRoot ? profileSalary[0].orgRoot : null, // ]; if (record.leaveType == "RETIRE") { - _profileSalary = record?.profileSalary.length > 1 - ? record?.profileSalary[1] - : null; + _profileSalary = profileSalary.length > 1 + ? profileSalary[1] + : profileSalary.length > 0 + ? profileSalary[0] + : null; } else { - _profileSalary = record?.profileSalary[0]; + _profileSalary = profileSalary.length > 0 + ? profileSalary[0] + : null } if (_profileSalary) { _OrgLeave = [ @@ -435,11 +439,15 @@ export class ProfileGovernmentEmployeeController extends Controller { // profileSalary.length > 0 && profileSalary[0].orgRoot ? profileSalary[0].orgRoot : null, // ]; if (record.leaveType == "RETIRE") { - _profileSalary = record?.profileSalary.length > 1 - ? record?.profileSalary[1] - : null; + _profileSalary = profileSalary.length > 1 + ? profileSalary[1] + : profileSalary.length > 0 + ? profileSalary[0] + : null; } else { - _profileSalary = record?.profileSalary[0]; + _profileSalary = profileSalary.length > 0 + ? profileSalary[0] + : null; } if (_profileSalary) { _OrgLeave = [