From 53e6d6fb48db68e6b7f12989e0a8a14a14b1b998 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Fri, 3 Oct 2025 16:44:43 +0700 Subject: [PATCH] fix script retire and fix bug filter registry retire --- src/controllers/CommandController.ts | 90 +++++++++++++--------------- src/services/ProfileLeaveService.ts | 5 +- 2 files changed, 41 insertions(+), 54 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 7c385db0..049518bb 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -264,7 +264,7 @@ export class CommandController extends Controller { yearKeyword = match[1].trim(); } let yearInBC = yearKeyword ? parseInt(yearKeyword) - 543 : null; - + // const [commands, total] = await this.commandRepository let query = await this.commandRepository .createQueryBuilder("command") @@ -335,16 +335,13 @@ export class CommandController extends Controller { ); }), ) - .orderBy("command.createdAt", "DESC") + .orderBy("command.createdAt", "DESC"); - if (sortBy) { - query = query.orderBy( - `command.${sortBy}`, - descending ? "DESC" : "ASC" - ); - } + if (sortBy) { + query = query.orderBy(`command.${sortBy}`, descending ? "DESC" : "ASC"); + } - let [commands, total] = await query + let [commands, total] = await query .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); @@ -1500,7 +1497,7 @@ export class CommandController extends Controller { const today = new Date(); today.setUTCHours(0, 0, 0, 0); let type: string = "OFFICER"; - let _Date = new Date() + let _Date = new Date(); try { const response_ = await axios.get( process.env.API_URL + `/retirement/update-status/${type}/${today.getFullYear()}`, @@ -1513,15 +1510,17 @@ export class CommandController extends Controller { }, ); if (response_ && response_.data.result) { - let signDate:string = "" + let signDate: string = ""; if (response_.data.result.signDate != null) { - signDate = Extension.ToThaiShortDate_noPrefix(new Date(response_.data.result.signDate)) + signDate = Extension.ToThaiShortDate_noPrefix(new Date(response_.data.result.signDate)); + } else { + signDate = Extension.ToThaiShortDate_noPrefix(_Date); } - else { - signDate = Extension.ToThaiShortDate_noPrefix(_Date) - } - 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") + 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 }); @@ -1533,7 +1532,7 @@ export class CommandController extends Controller { // console.log("3. แก้ไขสถานะในทะเบียนประวัติ") _profile.isRetirement = true; _profile.isLeave = true; - _profile.isActive = false + _profile.isActive = false; _profile.leaveType = "RETIRE"; _profile.leaveReason = "เกษียณอายุราชการ"; _profile.leaveDate = _Date; @@ -1568,12 +1567,11 @@ export class CommandController extends Controller { }, ); if (response_ && response_.data.result) { - let signDate:string = "" + let signDate: string = ""; if (response_.data.result.signDate != null) { - signDate = Extension.ToThaiShortDate_noPrefix(new Date(response_.data.result.signDate)) - } - else { - signDate = Extension.ToThaiShortDate_noPrefix(_Date) + signDate = Extension.ToThaiShortDate_noPrefix(new Date(response_.data.result.signDate)); + } else { + signDate = Extension.ToThaiShortDate_noPrefix(_Date); } await Promise.all( @@ -1587,7 +1585,7 @@ export class CommandController extends Controller { // แก้ไขสถานะในทะเบียนประวัติ _profileEmp.isRetirement = true; _profileEmp.isLeave = true; - _profileEmp.isActive = false + _profileEmp.isActive = false; _profileEmp.leaveType = "RETIRE"; _profileEmp.leaveReason = "เกษียณอายุราชการ"; _profileEmp.leaveDate = _Date; @@ -1612,9 +1610,8 @@ export class CommandController extends Controller { } async profileSalaryRetire(profileId: string, type: string, signDate: string, _Date: Date) { - const whereKey = type == "OFFICER" - ? { profileId: profileId } - : { profileEmployeeId: profileId }; + const whereKey = + type == "OFFICER" ? { profileId: profileId } : { profileEmployeeId: profileId }; const maxOrder = await this.salaryRepo.findOne({ select: { order: true }, where: whereKey, @@ -1657,8 +1654,7 @@ export class CommandController extends Controller { if (type == "OFFICER") { data.profileId = profileId; data.profileEmployeeId = null; - } - else if (type == "EMPLOYEE"){ + } else if (type == "EMPLOYEE") { data.profileEmployeeId = profileId; data.profileId = null; } @@ -1668,12 +1664,12 @@ export class CommandController extends Controller { } async posMasterRetire(profileId: string, type: string, _Date: Date) { - const orgRevision = await this.orgRevisionRepo.findOne({ - where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false } + const orgRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, }); if (orgRevision) { - let _posMaster:any = null; - let _position:any = null; + let _posMaster: any = null; + let _position: any = null; if (type == "OFFICER") { _posMaster = await this.posMasterRepository.findOne({ where: { @@ -1683,10 +1679,10 @@ export class CommandController extends Controller { }); if (_posMaster) { _position = await this.positionRepository.findOne({ - where: { + where: { posMasterId: _posMaster.id, - positionIsSelected: true - } + positionIsSelected: true, + }, }); if (_position) { _position.positionIsSelected = false; @@ -1694,15 +1690,13 @@ export class CommandController extends Controller { _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") { + } else if (type == "EMPLOYEE") { _posMaster = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: orgRevision.id, @@ -1711,10 +1705,10 @@ export class CommandController extends Controller { }); if (_posMaster) { _position = await this.employeePositionRepository.findOne({ - where: { + where: { posMasterId: _posMaster.id, - positionIsSelected: true - } + positionIsSelected: true, + }, }); if (_position) { _position.positionIsSelected = false; @@ -1722,7 +1716,6 @@ export class CommandController extends Controller { _position.lastUpdatedAt = _Date; await this.employeePositionRepository.save(_position); } - _posMaster.isSit = false; _posMaster.current_holderId = null; _posMaster.lastUpdateFullName = "System Administrator"; _posMaster.lastUpdatedAt = _Date; @@ -3207,13 +3200,10 @@ export class CommandController extends Controller { where: { refId: In(_refId) }, }); // 2. ดึง commandId ที่ไม่ซ้ำ - const commandIds = Array.from(new Set(commandRecives.map(x => x.commandId).filter(Boolean))); + const commandIds = Array.from(new Set(commandRecives.map((x) => x.commandId).filter(Boolean))); // 3. อัปเดต status ของ command if (commandIds.length > 0) { - await this.commandRepository.update( - { id: In(commandIds) }, - { status: "CANCEL" } - ); + await this.commandRepository.update({ id: In(commandIds) }, { status: "CANCEL" }); } return new HttpSuccess(); } @@ -3723,7 +3713,7 @@ export class CommandController extends Controller { if (commandRecive && commandRecive.commandId) { await this.commandRepository.update( { id: commandRecive?.commandId }, - { status: "CANCEL" } + { status: "CANCEL" }, ); } } @@ -4059,7 +4049,7 @@ export class CommandController extends Controller { if (commandRecive && commandRecive.commandId) { await this.commandRepository.update( { id: commandRecive?.commandId }, - { status: "CANCEL" } + { status: "CANCEL" }, ); } } diff --git a/src/services/ProfileLeaveService.ts b/src/services/ProfileLeaveService.ts index c53c475f..42905093 100644 --- a/src/services/ProfileLeaveService.ts +++ b/src/services/ProfileLeaveService.ts @@ -571,10 +571,7 @@ export class ProfileLeaveService { } if (posLevel) { - queryBuilder.andWhere( - "CONCAT(posType.posTypeShortName, ' ', posLevel.posLevelName) LIKE :keyword2", - { keyword2: `${posLevel}` }, - ); + queryBuilder.andWhere("posLevel.posLevelName LIKE :keyword2", { keyword2: `${posLevel}` }); } if (isProbation !== undefined && isProbation !== null) {