From 89e94b300620681d05f143ce2e83cc475614c3cd Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 1 Feb 2024 16:41:24 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=E0=B8=9F=E0=B8=B4=E0=B8=A5=E0=B8=94=E0=B9=8C=20Total?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/OrganizationController.ts | 39 +++++++++++++++++++---- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 4b2bbb24..8966a0ba 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -703,7 +703,8 @@ export class OrganizationController extends Controller { .getMany() : []; - const formattedData = orgRootData.map((orgRoot) => { + // const formattedData = orgRootData.map((orgRoot) => { + const formattedData = await Promise.all(orgRootData.map(async (orgRoot) => { return { orgTreeId: orgRoot.id, orgLevel: 0, @@ -719,9 +720,15 @@ export class OrganizationController extends Controller { orgTreeFax: orgRoot.orgRootFax, orgRevisionId: orgRoot.orgRevisionId, orgRootName: orgRoot.orgRootName, + totalPosition: await this.posMasterRepository.count({ where: { orgRootId: orgRoot.id }}), + totalPositionCurrentUse: await this.posMasterRepository.count({ where: { orgRootId: orgRoot.id, profileIdCurrentHolder: Not(IsNull()) && Not("") }}), + totalPositionCurrentVacant: await this.posMasterRepository.count({ where: { orgRootId: orgRoot.id, profileIdCurrentHolder: IsNull() && "" }}), + totalPositionNextUse: await this.posMasterRepository.count({ where: { orgRootId: orgRoot.id, profileIdNextHolder: Not(IsNull()) && Not("") }}), + totalPositionNextVacant: await this.posMasterRepository.count({ where: { orgRootId: orgRoot.id, profileIdNextHolder: IsNull() && "" }}), + children: orgChild1Data .filter((orgChild1) => orgChild1.orgRootId === orgRoot.id) - .map((orgChild1) => ({ + .map(async (orgChild1) => ({ orgTreeId: orgChild1.id, orgRootId: orgRoot.id, orgLevel: 1, @@ -738,9 +745,14 @@ export class OrganizationController extends Controller { orgTreeFax: orgChild1.orgChild1Fax, orgRevisionId: orgRoot.orgRevisionId, orgRootName: orgRoot.orgRootName, + totalPosition: await this.posMasterRepository.count({ where: { orgChild1Id: orgChild1.id }}), + totalPositionCurrentUse: await this.posMasterRepository.count({ where: { orgChild1Id: orgChild1.id, profileIdCurrentHolder: Not(IsNull()) && Not("") }}), + totalPositionCurrentVacant: await this.posMasterRepository.count({ where: { orgChild1Id: orgChild1.id, profileIdCurrentHolder: IsNull() && "" }}), + totalPositionNextUse: await this.posMasterRepository.count({ where: { orgChild1Id: orgChild1.id, profileIdNextHolder: Not(IsNull()) && Not("") }}), + totalPositionNextVacant: await this.posMasterRepository.count({ where: { orgChild1Id: orgChild1.id, profileIdNextHolder: IsNull() && "" }}), children: orgChild2Data .filter((orgChild2) => orgChild2.orgChild1Id === orgChild1.id) - .map((orgChild2) => ({ + .map(async (orgChild2) => ({ orgTreeId: orgChild2.id, orgRootId: orgChild1.id, orgLevel: 2, @@ -757,9 +769,14 @@ export class OrganizationController extends Controller { orgTreeFax: orgChild2.orgChild2Fax, orgRevisionId: orgRoot.orgRevisionId, orgRootName: orgRoot.orgRootName, + totalPosition: await this.posMasterRepository.count({ where: { orgChild2Id: orgChild2.id }}), + totalPositionCurrentUse: await this.posMasterRepository.count({ where: { orgChild2Id: orgChild2.id, profileIdCurrentHolder: Not(IsNull()) && Not("") }}), + totalPositionCurrentVacant: await this.posMasterRepository.count({ where: { orgChild2Id: orgChild2.id, profileIdCurrentHolder: IsNull() && "" }}), + totalPositionNextUse: await this.posMasterRepository.count({ where: { orgChild2Id: orgChild2.id, profileIdNextHolder: Not(IsNull()) && Not("") }}), + totalPositionNextVacant: await this.posMasterRepository.count({ where: { orgChild2Id: orgChild2.id, profileIdNextHolder: IsNull() && "" }}), children: orgChild3Data .filter((orgChild3) => orgChild3.orgChild2Id === orgChild2.id) - .map((orgChild3) => ({ + .map(async (orgChild3) => ({ orgTreeId: orgChild3.id, orgRootId: orgChild2.id, orgLevel: 3, @@ -776,9 +793,14 @@ export class OrganizationController extends Controller { orgTreeFax: orgChild3.orgChild3Fax, orgRevisionId: orgRoot.orgRevisionId, orgRootName: orgRoot.orgRootName, + totalPosition: await this.posMasterRepository.count({ where: { orgChild3Id: orgChild3.id }}), + totalPositionCurrentUse: await this.posMasterRepository.count({ where: { orgChild3Id: orgChild3.id, profileIdCurrentHolder: Not(IsNull()) && Not("") }}), + totalPositionCurrentVacant: await this.posMasterRepository.count({ where: { orgChild3Id: orgChild3.id, profileIdCurrentHolder: IsNull() && "" }}), + totalPositionNextUse: await this.posMasterRepository.count({ where: { orgChild3Id: orgChild3.id, profileIdNextHolder: Not(IsNull()) && Not("") }}), + totalPositionNextVacant: await this.posMasterRepository.count({ where: { orgChild3Id: orgChild3.id, profileIdNextHolder: IsNull() && "" }}), children: orgChild4Data .filter((orgChild4) => orgChild4.orgChild3Id === orgChild3.id) - .map((orgChild4) => ({ + .map(async (orgChild4) => ({ orgTreeId: orgChild4.id, orgRootId: orgChild3.id, orgLevel: 4, @@ -795,12 +817,17 @@ export class OrganizationController extends Controller { orgTreeFax: orgChild4.orgChild4Fax, orgRevisionId: orgRoot.orgRevisionId, orgRootName: orgRoot.orgRootName, + totalPosition: await this.posMasterRepository.count({ where: { orgChild4Id: orgChild4.id }}), + totalPositionCurrentUse: await this.posMasterRepository.count({ where: { orgChild4Id: orgChild4.id, profileIdCurrentHolder: Not(IsNull()) && Not("") }}), + totalPositionCurrentVacant: await this.posMasterRepository.count({ where: { orgChild4Id: orgChild4.id, profileIdCurrentHolder: IsNull() && "" }}), + totalPositionNextUse: await this.posMasterRepository.count({ where: { orgChild4Id: orgChild4.id, profileIdNextHolder: Not(IsNull()) && Not("") }}), + totalPositionNextVacant: await this.posMasterRepository.count({ where: { orgChild4Id: orgChild4.id, profileIdNextHolder: IsNull() && "" }}), })), })), })), })), }; - }); + })); return new HttpSuccess(formattedData); } catch (error) {