From e2ca88a98828e27f08f39ee13059b097a545766f Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Tue, 8 Apr 2025 18:00:05 +0700 Subject: [PATCH] salary-leave-discipline --- src/controllers/CommandController.ts | 288 ++++++++++++++------------- 1 file changed, 151 insertions(+), 137 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index ebe4f2a7..5e9410cd 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -3743,6 +3743,13 @@ export class CommandController extends Controller { commandCode?: string | null; commandName?: string | null; remark: string | null; + orgRoot?: string | null; + orgChild1?: string | null; + orgChild2?: string | null; + orgChild3?: string | null; + orgChild4?: string | null; + posNo?: string | null; + posNoAbb?: string | null; }[]; }, ) { @@ -3778,41 +3785,41 @@ export class CommandController extends Controller { orgRevisionIsDraft: false, }, }); - 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; - const orgChild3Ref = orgRevisionRef?.orgChild3 ?? null; - const orgChild4Ref = orgRevisionRef?.orgChild4 ?? null; - const shortName = - !profile.current_holders || profile.current_holders.length == 0 - ? null - : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null && - profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - ?.orgChild4 != null - ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}` - : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null && - profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - ?.orgChild3 != null - ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}` - : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != - null && - profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - ?.orgChild2 != null - ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}` - : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != - null && - profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - ?.orgChild1 != null - ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}` - : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != - null && - profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - ?.orgRoot != null - ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` - : null; - const posNo = `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`; + // 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; + // const orgChild3Ref = orgRevisionRef?.orgChild3 ?? null; + // const orgChild4Ref = orgRevisionRef?.orgChild4 ?? null; + // const shortName = + // !profile.current_holders || profile.current_holders.length == 0 + // ? null + // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null && + // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + // ?.orgChild4 != null + // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}` + // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null && + // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + // ?.orgChild3 != null + // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}` + // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != + // null && + // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + // ?.orgChild2 != null + // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}` + // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != + // null && + // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + // ?.orgChild1 != null + // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}` + // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != + // null && + // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + // ?.orgRoot != null + // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` + // : null; + // const posNo = `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`; let position = profile.current_holders .filter((x) => x.orgRevisionId == orgRevision?.id)[0] @@ -3837,11 +3844,11 @@ export class CommandController extends Controller { ? profile.profileSalary[0].order + 1 : 1 : null, - orgRoot: orgRootRef?.orgRootName ?? null, - orgChild1: orgChild1Ref?.orgChild1Name ?? null, - orgChild2: orgChild2Ref?.orgChild2Name ?? null, - orgChild3: orgChild3Ref?.orgChild3Name ?? null, - orgChild4: orgChild4Ref?.orgChild4Name ?? null, + orgRoot: item.orgRoot, + orgChild1: item.orgChild1, + orgChild2: item.orgChild2, + orgChild3: item.orgChild3, + orgChild4: item.orgChild4, createdUserId: req.user.sub, createdFullName: req.user.name, lastUpdateUserId: req.user.sub, @@ -3852,8 +3859,8 @@ export class CommandController extends Controller { isGovernment: item.isGovernment, commandNo: item.commandNo, commandYear: item.commandYear, - posNo: posNo ?? null, - posNoAbb: shortName ?? null, + posNo: item.posNo, + posNoAbb: item.posNoAbb, commandDateAffect: item.commandDateAffect, commandDateSign: item.commandDateSign, commandCode: item.commandCode, @@ -3965,47 +3972,47 @@ export class CommandController extends Controller { 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) => x.orgRevisionId == orgRevision?.id) ?? null; - const orgRootRef = orgRevisionRef?.orgRoot ?? null; - const orgChild1Ref = orgRevisionRef?.orgChild1 ?? null; - const orgChild2Ref = orgRevisionRef?.orgChild2 ?? null; - const orgChild3Ref = orgRevisionRef?.orgChild3 ?? null; - const orgChild4Ref = orgRevisionRef?.orgChild4 ?? null; - const shortName = - !profile.current_holders || profile.current_holders.length == 0 - ? null - : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null && - profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - ?.orgChild4 != null - ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}` - : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null && - profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - ?.orgChild3 != null - ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}` - : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != - null && - profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - ?.orgChild2 != null - ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}` - : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != - null && - profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - ?.orgChild1 != null - ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}` - : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != - null && - profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - ?.orgRoot != null - ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` - : null; - const posNo = `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`; + // const orgRevision = await this.orgRevisionRepo.findOne({ + // where: { + // orgRevisionIsCurrent: true, + // orgRevisionIsDraft: false, + // }, + // }); + // 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; + // const orgChild3Ref = orgRevisionRef?.orgChild3 ?? null; + // const orgChild4Ref = orgRevisionRef?.orgChild4 ?? null; + // const shortName = + // !profile.current_holders || profile.current_holders.length == 0 + // ? null + // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null && + // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + // ?.orgChild4 != null + // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}` + // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null && + // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + // ?.orgChild3 != null + // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}` + // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != + // null && + // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + // ?.orgChild2 != null + // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}` + // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != + // null && + // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + // ?.orgChild1 != null + // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}` + // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != + // null && + // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + // ?.orgRoot != null + // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` + // : null; + // const posNo = `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`; // let position = // profile.current_holders // .filter((x) => x.orgRevisionId == orgRevision?.id)[0] @@ -4028,11 +4035,11 @@ export class CommandController extends Controller { ? profile.profileSalary[0].order + 1 : 1 : null, - orgRoot: orgRootRef?.orgRootName ?? null, - orgChild1: orgChild1Ref?.orgChild1Name ?? null, - orgChild2: orgChild2Ref?.orgChild2Name ?? null, - orgChild3: orgChild3Ref?.orgChild3Name ?? null, - orgChild4: orgChild4Ref?.orgChild4Name ?? null, + orgRoot: item.orgRoot, + orgChild1: item.orgChild1, + orgChild2: item.orgChild2, + orgChild3: item.orgChild3, + orgChild4: item.orgChild4, createdUserId: req.user.sub, createdFullName: req.user.name, lastUpdateUserId: req.user.sub, @@ -4043,8 +4050,8 @@ export class CommandController extends Controller { isGovernment: item.isGovernment, commandNo: item.commandNo, commandYear: item.commandYear, - posNo: posNo ?? null, - posNoAbb: shortName ?? null, + posNo: item.posNo, + posNoAbb: item.posNoAbb, commandDateAffect: item.commandDateAffect, commandDateSign: item.commandDateSign, commandCode: item.commandCode, @@ -4170,6 +4177,13 @@ export class CommandController extends Controller { commandCode?: string | null; commandName?: string | null; remark: string | null; + orgRoot?: string | null; + orgChild1?: string | null; + orgChild2?: string | null; + orgChild3?: string | null; + orgChild4?: string | null; + posNo?: string | null; + posNoAbb?: string | null; }[]; }, ) { @@ -4198,46 +4212,46 @@ export class CommandController extends Controller { 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) => x.orgRevisionId == orgRevision?.id) ?? null; - const orgRootRef = orgRevisionRef?.orgRoot ?? null; - const orgChild1Ref = orgRevisionRef?.orgChild1 ?? null; - const orgChild2Ref = orgRevisionRef?.orgChild2 ?? null; - const orgChild3Ref = orgRevisionRef?.orgChild3 ?? null; - const orgChild4Ref = orgRevisionRef?.orgChild4 ?? null; - const shortName = - !profile.current_holders || profile.current_holders.length == 0 - ? null - : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null && - profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - ?.orgChild4 != null - ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}` - : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null && - profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - ?.orgChild3 != null - ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}` - : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null && - profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - ?.orgChild2 != null - ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}` - : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != - null && - profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - ?.orgChild1 != null - ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}` - : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != - null && - profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - ?.orgRoot != null - ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` - : null; - const posNo = `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`; + // const orgRevision = await this.orgRevisionRepo.findOne({ + // where: { + // orgRevisionIsCurrent: true, + // orgRevisionIsDraft: false, + // }, + // }); + // 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; + // const orgChild3Ref = orgRevisionRef?.orgChild3 ?? null; + // const orgChild4Ref = orgRevisionRef?.orgChild4 ?? null; + // const shortName = + // !profile.current_holders || profile.current_holders.length == 0 + // ? null + // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null && + // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + // ?.orgChild4 != null + // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}` + // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null && + // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + // ?.orgChild3 != null + // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}` + // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null && + // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + // ?.orgChild2 != null + // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}` + // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != + // null && + // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + // ?.orgChild1 != null + // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}` + // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != + // null && + // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + // ?.orgRoot != null + // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` + // : null; + // const posNo = `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`; // let position = // profile.current_holders // .filter((x) => x.orgRevisionId == orgRevision?.id)[0] @@ -4260,11 +4274,11 @@ export class CommandController extends Controller { ? profile.profileSalary[0].order + 1 : 1 : null, - orgRoot: orgRootRef?.orgRootName ?? null, - orgChild1: orgChild1Ref?.orgChild1Name ?? null, - orgChild2: orgChild2Ref?.orgChild2Name ?? null, - orgChild3: orgChild3Ref?.orgChild3Name ?? null, - orgChild4: orgChild4Ref?.orgChild4Name ?? null, + orgRoot: item.orgRoot, + orgChild1: item.orgChild1, + orgChild2: item.orgChild2, + orgChild3: item.orgChild3, + orgChild4: item.orgChild4, createdUserId: req.user.sub, createdFullName: req.user.name, lastUpdateUserId: req.user.sub, @@ -4275,8 +4289,8 @@ export class CommandController extends Controller { isGovernment: item.isGovernment, commandNo: item.commandNo, commandYear: item.commandYear, - posNo: posNo, - posNoAbb: shortName, + posNo: item.posNo, + posNoAbb: item.posNoAbb, commandDateAffect: item.commandDateAffect, commandDateSign: item.commandDateSign, commandCode: item.commandCode,