เพิ่มฟิลด์ Total

This commit is contained in:
Bright 2024-02-01 16:41:24 +07:00
parent c90319d010
commit 89e94b3006

View file

@ -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) {