From 1b3f42fd855d43e841874c555ae2ce7aba64fb67 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 28 Oct 2024 18:01:36 +0700 Subject: [PATCH] =?UTF-8?q?fix=20=E0=B8=9B=E0=B8=A5=E0=B8=94=E0=B8=88?= =?UTF-8?q?=E0=B8=B2=E0=B8=81=E0=B8=81=E0=B8=B4=E0=B9=88=E0=B8=87=20?= =?UTF-8?q?=E0=B8=A2=E0=B8=81=E0=B9=80=E0=B8=A7=E0=B9=89=E0=B8=99=E0=B8=84?= =?UTF-8?q?=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=8725=2026?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 6 ++++-- src/interfaces/utils.ts | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 9e654ffe..033e9133 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -39,6 +39,7 @@ import { commandTypePath, removeProfileInOrganize, setLogDataDiff, + checkExceptCommandType, checkCommandType, } from "../interfaces/utils"; import { Position } from "../entities/Position"; @@ -2113,7 +2114,7 @@ export class CommandController extends Controller { // ประวัติตำแหน่ง const data = new ProfileSalary(); const meta = { - profileId: item.profileId, + profileId: profile.id, date: item.date, refCommandNo: item.refCommandNo, templateDoc: item.salaryRef, @@ -2185,7 +2186,8 @@ export class CommandController extends Controller { profile.lastUpdateUserId = req.user.sub; profile.lastUpdateFullName = req.user.name; profile.lastUpdatedAt = new Date(); - if (item.isLeave == true) { + const exceptClear = await checkExceptCommandType(String(item.commandId)); + if (item.isLeave == true && !exceptClear) { await removeProfileInOrganize(profile.id, "OFFICER"); } const clearProfile = await checkCommandType(String(item.commandId)); diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index 826df67f..1c31504c 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -175,6 +175,20 @@ export async function removeProfileInOrganize(profileId: string, type: string) { } } +export async function checkExceptCommandType(commandId: string) { + const commandRepository = AppDataSource.getRepository(Command); + const _type = await commandRepository.findOne({ + where: { + id: commandId + }, + relations: ["commandType"], + }); + if (!["C-PM-25", "C-PM-26"].includes(String(_type?.commandType.code))) { + return false; + } + return true; +} + export async function checkCommandType(commandId: string) { const commandRepository = AppDataSource.getRepository(Command); const _type = await commandRepository.findOne({