diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index e4538538..29b9533c 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -4266,12 +4266,22 @@ export class CommandController extends Controller { body.data.map(async (item) => { const profile: any = await this.profileRepository.findOne({ where: { id: item.profileId }, - relations: ["roleKeycloaks"], + relations: ["roleKeycloaks","current_holders"], }); if (!profile) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); } + const orgRevision = await this.orgRevisionRepo.findOne({ + where: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + }); + + const orgRevisionRef = + profile?.current_holders?.find((x:any) => x.orgRevisionId == orgRevision?.id) ?? null; + //ลบตำแหน่งที่รักษาการแทน const code = _command?.commandType?.code; if (code && ["C-PM-13"].includes(code)) { @@ -4300,6 +4310,9 @@ export class CommandController extends Controller { lastUpdatedAt: new Date(), }; if (item.isLeave != undefined && item.isLeave == true) { + if(orgRevisionRef){ + await CreatePosMasterHistoryOfficer(orgRevisionRef.id, req, "DELETE"); + } await removeProfileInOrganize(profile.id, "OFFICER"); } const clearProfile = await checkCommandType(String(item.commandId)); @@ -4628,8 +4641,8 @@ export class CommandController extends Controller { orgRevisionIsDraft: false, }, }); - // const orgRevisionRef = - // profile?.current_holders?.find((x) => x.orgRevisionId == orgRevision?.id) ?? null; + const orgRevisionRef = + profile?.current_holders?.find((x) => x.orgRevisionId == orgRevision?.id) ?? null; // const orgRootRef = orgRevisionRef?.orgRoot ?? null; // const orgChild1Ref = orgRevisionRef?.orgChild1 ?? null; // const orgChild2Ref = orgRevisionRef?.orgChild2 ?? null; @@ -4770,6 +4783,9 @@ export class CommandController extends Controller { _profile.leaveDate = item.commandDateAffect ?? _null; _profile.leaveType = exceptClear.LeaveType ?? _null; } else { + if(orgRevisionRef){ + await CreatePosMasterHistoryOfficer(orgRevisionRef.id, req, "DELETE"); + } await removeProfileInOrganize(_profile.id, "OFFICER"); } }