From 62750576d385ceb7c08523da1f378ae3c9801fcc Mon Sep 17 00:00:00 2001 From: Adisak Date: Wed, 12 Nov 2025 18:02:28 +0700 Subject: [PATCH] update --- src/controllers/CommandController.ts | 2 -- src/interfaces/utils.ts | 22 +++++++--------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index e7f883d0..29b9533c 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -4313,9 +4313,7 @@ export class CommandController extends Controller { if(orgRevisionRef){ await CreatePosMasterHistoryOfficer(orgRevisionRef.id, req, "DELETE"); } - console.log("A"); await removeProfileInOrganize(profile.id, "OFFICER"); - console.log("Z"); } const clearProfile = await checkCommandType(String(item.commandId)); const _null: any = null; diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index f5c9e608..12636a36 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -253,73 +253,65 @@ export function calculateRetireYear(birthDate: Date) { return yy + 61; } export async function removeProfileInOrganize(profileId: string, type: string) { - console.log(1); const currentRevision = await AppDataSource.getRepository(OrgRevision) .createQueryBuilder("orgRevision") .where("orgRevision.orgRevisionIsDraft = false") .andWhere("orgRevision.orgRevisionIsCurrent = true") .getOne(); - console.log(2); + const draftRevision = await AppDataSource.getRepository(OrgRevision) .createQueryBuilder("orgRevision") .where("orgRevision.orgRevisionIsDraft = true") .andWhere("orgRevision.orgRevisionIsCurrent = false") .getOne(); - console.log(3); + if (!currentRevision && !draftRevision) { - console.log(4); return; } if (type === "OFFICER") { - console.log(5); const findProfileInposMaster = await AppDataSource.getRepository(PosMaster) .createQueryBuilder("posMaster") .where("posMaster.orgRevisionId = :orgRevisionId", { orgRevisionId: currentRevision?.id }) .andWhere("posMaster.current_holderId = :profileId", { profileId }) .getOne(); - console.log(6); + await AppDataSource.getRepository(PosMaster) .createQueryBuilder() .update(PosMaster) .set({ current_holderId: null }) .where("id = :id", { id: findProfileInposMaster?.id }) .execute(); - console.log(7); + const findProfileInposMasterDraft = await AppDataSource.getRepository(PosMaster) .createQueryBuilder("posMaster") .where("posMaster.orgRevisionId = :orgRevisionId", { orgRevisionId: draftRevision?.id }) .andWhere("posMaster.next_holderId = :profileId", { profileId }) .getOne(); - console.log(8); + await AppDataSource.getRepository(PosMaster) .createQueryBuilder() .update(PosMaster) .set({ next_holderId: null }) .where("id = :id", { id: findProfileInposMasterDraft?.id }) .execute(); - console.log(9); + if (!findProfileInposMaster && !findProfileInposMasterDraft) { - console.log(10); return; } - console.log(11); const findPosition = await AppDataSource.getRepository(Position) .createQueryBuilder("position") .where("position.posMasterId = :posMasterId", { posMasterId: findProfileInposMaster?.id }) .getMany(); - console.log(12); + if (!findPosition) { - console.log(13); return; } - console.log(13); await AppDataSource.getRepository(Position) .createQueryBuilder() .update(Position) .set({ positionIsSelected: false }) .where("id IN (:...ids)", { ids: findPosition.map((item) => item.id) }) .execute(); - console.log(14); } if (type === "EMPLOYEE") { const findProfileInEmpPosMaster = await AppDataSource.getRepository(EmployeePosMaster)