From 755ae992ddc29e8d2abb6b2af1c4fe6de97a7efd Mon Sep 17 00:00:00 2001 From: Adisak Date: Fri, 29 May 2026 10:12:46 +0700 Subject: [PATCH] =?UTF-8?q?#246=20=E0=B9=80=E0=B8=AA=E0=B8=A3=E0=B8=B4?= =?UTF-8?q?=E0=B8=A1=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87?= =?UTF-8?q?=20C-PM-25,C-PM-26?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 89 +++++++++------------------- src/interfaces/utils.ts | 51 ++++------------ 2 files changed, 42 insertions(+), 98 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index f114a24c..d732a622 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -41,7 +41,6 @@ import { removeProfileInOrganize, setLogDataDiff, checkReturnCommandType, - checkExceptCommandType, checkCommandType, removePostMasterAct, logPositionIsSelectedChange, @@ -5629,20 +5628,10 @@ export class CommandController extends Controller { _profile.lastUpdateFullName = req.user.name; _profile.lastUpdatedAt = new Date(); if (item.isLeave == true) { - const exceptClear = await checkExceptCommandType(String(item.commandId)); - if (exceptClear.status) { - _profile.leaveReason = item.leaveReason ?? _null; - _profile.leaveCommandId = item.commandId ?? _null; - _profile.leaveCommandNo = `${item.commandNo}/${_commandYear}`; - _profile.leaveRemark = exceptClear.leaveRemark ?? _null; - _profile.leaveDate = item.commandDateAffect ?? _null; - _profile.leaveType = exceptClear.LeaveType ?? _null; - } else { - if (orgRevisionRef) { - await CreatePosMasterHistoryOfficer(orgRevisionRef.id, req, "DELETE"); - } - await removeProfileInOrganize(_profile.id, "OFFICER"); + if (orgRevisionRef) { + await CreatePosMasterHistoryOfficer(orgRevisionRef.id, req, "DELETE"); } + await removeProfileInOrganize(_profile.id, "OFFICER"); } const clearProfile = await checkCommandType(String(item.commandId)); if (clearProfile.status) { @@ -5821,32 +5810,22 @@ export class CommandController extends Controller { _profile.lastUpdateFullName = req.user.name; _profile.lastUpdatedAt = new Date(); if (item.isLeave == true) { - const exceptClear = await checkExceptCommandType(String(item.commandId)); - if (exceptClear.status) { - _profile.leaveReason = item.leaveReason ?? _null; - _profile.leaveCommandId = item.commandId ?? _null; - _profile.leaveCommandNo = `${item.commandNo}/${_commandYear}`; - _profile.leaveRemark = exceptClear.leaveRemark ?? _null; - _profile.leaveDate = item.commandDateAffect ?? _null; - _profile.leaveType = exceptClear.LeaveType ?? _null; - } else { - // บันทึกประวัติก่อนลบตำแหน่ง - const curRevision = await this.orgRevisionRepo.findOne({ - where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + // บันทึกประวัติก่อนลบตำแหน่ง + const curRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + }); + if (curRevision) { + const curPosMaster = await this.employeePosMasterRepository.findOne({ + where: { + current_holderId: _profile.id, + orgRevisionId: curRevision.id, + }, }); - if (curRevision) { - const curPosMaster = await this.employeePosMasterRepository.findOne({ - where: { - current_holderId: _profile.id, - orgRevisionId: curRevision.id, - }, - }); - if (curPosMaster) { - await CreatePosMasterHistoryEmployee(curPosMaster.id, req, "DELETE"); - } + if (curPosMaster) { + await CreatePosMasterHistoryEmployee(curPosMaster.id, req, "DELETE"); } - await removeProfileInOrganize(_profile.id, "EMPLOYEE"); } + await removeProfileInOrganize(_profile.id, "EMPLOYEE"); } const clearProfile = await checkCommandType(String(item.commandId)); if (clearProfile.status) { @@ -6166,32 +6145,22 @@ export class CommandController extends Controller { _profile.lastUpdateFullName = req.user.name; _profile.lastUpdatedAt = new Date(); if (item.isLeave == true) { - const exceptClear = await checkExceptCommandType(String(item.commandId)); - if (exceptClear.status) { - _profile.leaveReason = item.leaveReason ?? _null; - _profile.leaveCommandId = item.commandId ?? _null; - _profile.leaveCommandNo = `${item.commandNo}/${_commandYear}`; - _profile.leaveRemark = exceptClear.leaveRemark ?? _null; - _profile.leaveDate = item.commandDateAffect ?? _null; - _profile.leaveType = exceptClear.LeaveType ?? _null; - } else { - // บันทึกประวัติก่อนลบตำแหน่ง - const curRevision = await this.orgRevisionRepo.findOne({ - where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + // บันทึกประวัติก่อนลบตำแหน่ง + const curRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + }); + if (curRevision) { + const curPosMaster = await this.employeePosMasterRepository.findOne({ + where: { + current_holderId: _profile.id, + orgRevisionId: curRevision.id, + }, }); - if (curRevision) { - const curPosMaster = await this.employeePosMasterRepository.findOne({ - where: { - current_holderId: _profile.id, - orgRevisionId: curRevision.id, - }, - }); - if (curPosMaster) { - await CreatePosMasterHistoryEmployee(curPosMaster.id, req, "DELETE"); - } + if (curPosMaster) { + await CreatePosMasterHistoryEmployee(curPosMaster.id, req, "DELETE"); } - await removeProfileInOrganize(_profile.id, "EMPLOYEE"); } + await removeProfileInOrganize(_profile.id, "EMPLOYEE"); } const clearProfile = await checkCommandType(String(item.commandId)); if (clearProfile.status) { diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index c75bf147..3a48ab2b 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -326,7 +326,7 @@ export async function removeProfileInOrganize(profileId: string, type: string) { await AppDataSource.getRepository(EmployeePosMaster) .createQueryBuilder() .update(EmployeePosMaster) - .set({ current_holderId: null }) + .set({ current_holderId: null, isSit: false }) .where("id = :id", { id: findProfileInEmpPosMaster?.id }) .execute(); @@ -395,43 +395,6 @@ export async function checkReturnCommandType(commandId: string) { return true; } -export async function checkExceptCommandType(commandId: string) { - const commandRepository = AppDataSource.getRepository(Command); - const commandReciveRepository = AppDataSource.getRepository(CommandRecive); - const _type = await commandRepository.findOne({ - where: { - id: commandId, - }, - relations: ["commandType"], - }); - if (!["C-PM-25", "C-PM-26"].includes(String(_type?.commandType.code))) { - return { status: false, LeaveType: null, leaveRemark: null }; - } - const _commandRecive = await commandReciveRepository.findOne({ - where: { commandId: commandId }, - }); - - let _leaveType: string = ""; - switch (String(_type?.commandType.code)) { - case "C-PM-25": { - _leaveType = "DISCIPLINE_SUSPEND"; //คำสั่งพักจากราชการ - break; - } - case "C-PM-26": { - _leaveType = "DISCIPLINE_TEMP_SUSPEND"; //คำสั่งให้ออกจากราชการไว้ก่อน - break; - } - default: { - _leaveType = ""; - } - } - return { - status: true, - LeaveType: _leaveType, - leaveRemark: _commandRecive ? _commandRecive.remarkVertical : null, - }; -} - export async function checkCommandType(commandId: string) { const commandRepository = AppDataSource.getRepository(Command); const commandReciveRepository = AppDataSource.getRepository(CommandRecive); @@ -451,6 +414,8 @@ export async function checkCommandType(commandId: string) { "C-PM-23", "C-PM-19", "C-PM-20", + "C-PM-25", + "C-PM-26", "C-PM-43", ].includes(String(_type?.commandType.code)) ) { @@ -500,6 +465,16 @@ export async function checkCommandType(commandId: string) { _retireTypeName = "ลาออกจากราชการ"; break; } + case "C-PM-25": { + _leaveType = "DISCIPLINE_SUSPEND"; + _retireTypeName = "พักจากราชการ"; + break; + } + case "C-PM-26": { + _leaveType = "DISCIPLINE_TEMP_SUSPEND"; + _retireTypeName = "ให้ออกจากราชการไว้ก่อน"; + break; + } case "C-PM-43": { _leaveType = "RETIRE_OUT_EMP"; _retireTypeName = "ให้ออกจากราชการ";