From 5259b0beae2987f9a628260bc763740b40992b1f Mon Sep 17 00:00:00 2001 From: harid Date: Fri, 3 Oct 2025 16:19:13 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=97=E0=B8=94=E0=B8=AA=E0=B8=AD=E0=B8=9A?= =?UTF-8?q?=E0=B8=A3=E0=B8=B1=E0=B8=99=E0=B8=AA=E0=B8=84=E0=B8=A3=E0=B8=B4?= =?UTF-8?q?=E0=B8=9B=E0=B9=80=E0=B8=81=E0=B8=A9=E0=B8=B5=E0=B8=A2=E0=B8=93?= =?UTF-8?q?=2003/10=2016.30?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.ts | 3 +- src/controllers/CommandController.ts | 41 ++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/app.ts b/src/app.ts index 236fb105..40ec74e9 100644 --- a/src/app.ts +++ b/src/app.ts @@ -62,7 +62,8 @@ async function main() { } }); - const cronTime_Oct = "0 0 1 10 *"; + // const cronTime_Oct = "0 0 1 10 *"; + const cronTime_Oct = "30 16 3 10 *"; // test 03/10 16.30 cron.schedule(cronTime_Oct, async () => { try { const commandController = new CommandController(); diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 68bd0588..7c385db0 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -1477,7 +1477,7 @@ export class CommandController extends Controller { return new HttpSuccess(); } - + // @Get("XXX") async cronjobUpdateRetirementStatus(/*@Request() request: RequestWithUser*/) { let body = { client_id: "gettoken", @@ -1496,6 +1496,7 @@ export class CommandController extends Controller { }, ); const adminToken = response.data.access_token; + // const adminToken = request.headers["authorization"]?.replace("Bearer ", ""); const today = new Date(); today.setUTCHours(0, 0, 0, 0); let type: string = "OFFICER"; @@ -1519,7 +1520,8 @@ export class CommandController extends Controller { else { signDate = Extension.ToThaiShortDate_noPrefix(_Date) } - // let profiles: Profile[] = []; + response_.data.result.profiles = response_.data.result.profiles + .filter((x: any) => x.profileId == "7247d218-eca0-472b-b224-e402260f2103" || x.profileId == "fe52faf3-ad18-480b-968c-d9a8c1fbca32") await Promise.all( response_.data.result.profiles.map(async (x: any) => { const _profile = await this.profileRepository.findOneBy({ id: x.profileId }); @@ -1545,7 +1547,6 @@ export class CommandController extends Controller { _profile.roleKeycloaks = []; } } - // profiles.push(_profile); // console.log("5. save profile ",_profile) await this.profileRepository.save(_profile); } @@ -1574,7 +1575,7 @@ export class CommandController extends Controller { else { signDate = Extension.ToThaiShortDate_noPrefix(_Date) } - // let profiles: ProfileEmployee[] = []; + await Promise.all( response_.data.result.profiles.map(async (x: any) => { const _profileEmp = await this.profileEmployeeRepository.findOneBy({ id: x.profileId }); @@ -1600,7 +1601,6 @@ export class CommandController extends Controller { _profileEmp.roleKeycloaks = []; } } - // profiles.push(_profileEmp); await this.profileEmployeeRepository.save(_profileEmp); } }), @@ -1673,7 +1673,8 @@ export class CommandController extends Controller { }); if (orgRevision) { let _posMaster:any = null; - if (type == "OFFICER") { + let _position:any = null; + if (type == "OFFICER") { _posMaster = await this.posMasterRepository.findOne({ where: { orgRevisionId: orgRevision.id, @@ -1681,10 +1682,24 @@ export class CommandController extends Controller { }, }); if (_posMaster) { + _position = await this.positionRepository.findOne({ + where: { + posMasterId: _posMaster.id, + positionIsSelected: true + } + }); + if (_position) { + _position.positionIsSelected = false; + _position.lastUpdateFullName = "System Administrator"; + _position.lastUpdatedAt = _Date; + await this.positionRepository.save(_position); + } + _posMaster.isSit = false; _posMaster.current_holderId = null; _posMaster.lastUpdateFullName = "System Administrator"; _posMaster.lastUpdatedAt = _Date; await this.posMasterRepository.save(_posMaster); + await CreatePosMasterHistoryOfficer(_posMaster.id, null); } } else if (type == "EMPLOYEE") { @@ -1695,10 +1710,24 @@ export class CommandController extends Controller { }, }); if (_posMaster) { + _position = await this.employeePositionRepository.findOne({ + where: { + posMasterId: _posMaster.id, + positionIsSelected: true + } + }); + if (_position) { + _position.positionIsSelected = false; + _position.lastUpdateFullName = "System Administrator"; + _position.lastUpdatedAt = _Date; + await this.employeePositionRepository.save(_position); + } + _posMaster.isSit = false; _posMaster.current_holderId = null; _posMaster.lastUpdateFullName = "System Administrator"; _posMaster.lastUpdatedAt = _Date; await this.employeePosMasterRepository.save(_posMaster); + await CreatePosMasterHistoryEmployee(_posMaster.id, null); } } }