From 5eeb380e01857b2f6c05e58fbacc9a25db7a4441 Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Fri, 21 Mar 2025 17:14:45 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=AB=E0=B8=B2=E0=B8=84=E0=B8=99=E0=B8=AA?= =?UTF-8?q?=E0=B9=88=E0=B8=87=E0=B8=AA=E0=B8=B3=E0=B9=80=E0=B8=99=E0=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 112 +++++++++++++++++++++++---- 1 file changed, 98 insertions(+), 14 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 3e6be6b8..4a7e8785 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -2099,38 +2099,85 @@ export class CommandController extends Controller { .catch(() => {}); if (!["C-PM-10"].includes(commandCode)) { if (requestBody.persons != undefined && requestBody.persons.length > 0) { - let posMaster: any; - if (["C-PM-36", "C-PM-37"].includes(commandCode)) { - posMaster = await this.employeePosMasterRepository.find({ + let _orgRoot: any = []; + let _orgChild1: any = []; + let _orgChild2: any = []; + let _orgChild3: any = []; + let _orgChild4: any = []; + if ( + [ + "C-PM-21", + "C-PM-22", + "C-PM-23", + "C-PM-24", + "C-PM-34", + "C-PM-36", + "C-PM-37", + "C-PM-37", + "C-PM-37", + "C-PM-37", + ].includes(commandCode) + ) { + let posMaster = await this.employeePosMasterRepository.find({ where: { current_holderId: In(requestBody.persons.map((x) => x.profileId)), orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, }, - select: ["orgRootId"], + select: ["orgRootId", "orgChild1Id", "orgChild2Id", "orgChild3Id", "orgChild4Id"], }); + _orgRoot = posMaster + .filter((x) => x.orgRootId != null && x.orgRootId != "") + .map((x) => x.orgRootId); + _orgChild1 = posMaster + .filter((x) => x.orgChild1Id != null && x.orgChild1Id != "") + .map((x) => x.orgChild1Id); + _orgChild2 = posMaster + .filter((x) => x.orgChild2Id != null && x.orgChild2Id != "") + .map((x) => x.orgChild2Id); + _orgChild3 = posMaster + .filter((x) => x.orgChild3Id != null && x.orgChild3Id != "") + .map((x) => x.orgChild3Id); + _orgChild4 = posMaster + .filter((x) => x.orgChild4Id != null && x.orgChild4Id != "") + .map((x) => x.orgChild4Id); } else { var posMasterOfficer = await this.posMasterRepository.find({ where: { current_holderId: In(requestBody.persons.map((x) => x.profileId)), orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, }, - select: ["orgRootId"], + select: ["orgRootId", "orgChild1Id", "orgChild2Id", "orgChild3Id", "orgChild4Id"], }); var posMasterEmployee = await this.employeePosMasterRepository.find({ where: { current_holderId: In(requestBody.persons.map((x) => x.profileId)), orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, }, - select: ["orgRootId"], + select: ["orgRootId", "orgChild1Id", "orgChild2Id", "orgChild3Id", "orgChild4Id"], }); - posMaster = [...posMasterOfficer, ...posMasterEmployee]; + let posMaster = [...posMasterOfficer, ...posMasterEmployee]; + _orgRoot = posMaster + .filter((x) => x.orgRootId != null && x.orgRootId != "") + .map((x) => x.orgRootId); + _orgChild1 = posMaster + .filter((x) => x.orgChild1Id != null && x.orgChild1Id != "") + .map((x) => x.orgChild1Id); + _orgChild2 = posMaster + .filter((x) => x.orgChild2Id != null && x.orgChild2Id != "") + .map((x) => x.orgChild2Id); + _orgChild3 = posMaster + .filter((x) => x.orgChild3Id != null && x.orgChild3Id != "") + .map((x) => x.orgChild3Id); + _orgChild4 = posMaster + .filter((x) => x.orgChild4Id != null && x.orgChild4Id != "") + .map((x) => x.orgChild4Id); } let _posMaster: any; if (["C-PM-38", "C-PM-40"].includes(commandCode)) { _posMaster = await this.posMasterRepository.find({ where: { - orgRootId: In(posMaster.map((x: any) => x.orgRootId)), + orgRootId: In(_orgRoot), orgChild1: IsNull(), orgChild2: IsNull(), orgChild3: IsNull(), @@ -2143,12 +2190,48 @@ export class CommandController extends Controller { }); } else { _posMaster = await this.posMasterRepository.find({ - where: { - orgRootId: In(posMaster.map((x: any) => x.orgRootId)), - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - isDirector: true, - current_holderId: Not(IsNull()), - }, + where: [ + { + orgRootId: In(_orgRoot), + orgChild1: IsNull(), + orgChild2: IsNull(), + orgChild3: IsNull(), + orgChild4: IsNull(), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + isDirector: true, + current_holderId: Not(IsNull()), + }, + { + orgChild1: In(_orgChild1), + orgChild2: IsNull(), + orgChild3: IsNull(), + orgChild4: IsNull(), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + isDirector: true, + current_holderId: Not(IsNull()), + }, + { + orgChild2: In(_orgChild2), + orgChild3: IsNull(), + orgChild4: IsNull(), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + isDirector: true, + current_holderId: Not(IsNull()), + }, + { + orgChild3: In(_orgChild3), + orgChild4: IsNull(), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + isDirector: true, + current_holderId: Not(IsNull()), + }, + { + orgChild4: In(_orgChild3), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + isDirector: true, + current_holderId: Not(IsNull()), + }, + ], relations: ["current_holder", "orgRoot"], }); } @@ -2204,6 +2287,7 @@ export class CommandController extends Controller { .filter((x) => x.rootId != undefined && x.rootId != null && x.rootId != "") .map((x) => x.rootId), ), + orgChild1: IsNull(), orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, isDirector: true, current_holderId: Not(IsNull()),