diff --git a/src/app.ts b/src/app.ts index 34a58b5d..1ed0839f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -11,7 +11,6 @@ import { AppDataSource } from "./database/data-source"; import { RegisterRoutes } from "./routes"; import { OrganizationController } from "./controllers/OrganizationController"; import logMiddleware from "./middlewares/logs"; -import { run } from "node:test"; import { CommandController } from "./controllers/CommandController"; async function main() { diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 27315e6a..c71e0b9e 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -2500,7 +2500,7 @@ export class OrganizationController extends Controller { orgTreeFax: orgRoot.orgRootFax, orgRevisionId: orgRoot.orgRevisionId, orgRootName: orgRoot.orgRootName, - isDeputy:orgRoot.isDeputy, + isDeputy: orgRoot.isDeputy, responsibility: orgRoot.responsibility, labelName: orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName, @@ -3437,7 +3437,7 @@ export class OrganizationController extends Controller { today.setUTCHours(0, 0, 0, 0); // Set time to the beginning of the day const tomorrow = new Date(today); tomorrow.setDate(tomorrow.getDate() + 1); - + const orgRevisionPublish = await this.orgRevisionRepository .createQueryBuilder("orgRevision") .where("orgRevision.orgRevisionIsDraft = false") @@ -3450,7 +3450,7 @@ export class OrganizationController extends Controller { .andWhere("orgRevision.orgRevisionIsCurrent = false") .andWhere("orgRevision.orgPublishDate BETWEEN :today AND :tomorrow", { today, tomorrow }) .getOne(); - + if (!orgRevisionDraft) { return new HttpSuccess(); } @@ -3480,7 +3480,7 @@ export class OrganizationController extends Controller { lastUpdateUserId: "system", lastUpdateFullName: "system", lastUpdatedAt: new Date(), - } + }, }; sendToQueueOrg(msg); return new HttpSuccess(); @@ -3511,133 +3511,323 @@ export class OrganizationController extends Controller { where: { orgRevisionId: data.id, orgChild1Id: IsNull(), - current_holderId: Not(IsNull()), + // current_holderId: Not(IsNull()), }, relations: ["current_holder", "orgRoot"], + order: { posMasterOrder: "ASC" }, }); posMasterChild1 = await this.posMasterRepository.find({ where: { orgRevisionId: data.id, orgChild2Id: IsNull(), orgChild1Id: Not(IsNull()), - current_holderId: Not(IsNull()), + // current_holderId: Not(IsNull()), }, relations: ["current_holder", "orgChild1"], + order: { posMasterOrder: "ASC" }, }); posMasterChild2 = await this.posMasterRepository.find({ where: { orgRevisionId: data.id, orgChild3Id: IsNull(), orgChild2Id: Not(IsNull()), - current_holderId: Not(IsNull()), + // current_holderId: Not(IsNull()), }, relations: ["current_holder", "orgChild2"], + order: { posMasterOrder: "ASC" }, }); posMasterChild3 = await this.posMasterRepository.find({ where: { orgRevisionId: data.id, orgChild4Id: IsNull(), orgChild3Id: Not(IsNull()), - current_holderId: Not(IsNull()), + // current_holderId: Not(IsNull()), }, relations: ["current_holder", "orgChild3"], + order: { posMasterOrder: "ASC" }, }); posMasterChild4 = await this.posMasterRepository.find({ where: { orgRevisionId: data.id, orgChild4Id: Not(IsNull()), - current_holderId: Not(IsNull()), + // current_holderId: Not(IsNull()), }, relations: ["current_holder", "orgChild4"], + order: { posMasterOrder: "ASC" }, }); let formattedData = posMasterRoot - .filter((x: any) => x.current_holderId != null) - .map((x0: PosMaster) => ({ - personID: x0.current_holder.id, - name: x0.current_holder.firstName, - avatar: - x0.current_holder && - x0.current_holder.avatar != null && - x0.current_holder.avatarName != null - ? `${x0.current_holder.avatar}/${x0.current_holder.avatarName}` - : null, - positionName: x0.current_holder.position, - positionNum: x0.orgRoot.orgRootShortName + x0.posMasterNo, - positionNumInt: x0.posMasterNo, - departmentName: x0.orgRoot.orgRootName, - organizationId: x0.orgRoot.id, - children: posMasterChild1 - .filter((x: any) => x.current_holderId != null && x.orgRootId == x0.orgRootId) - .map((x1: PosMaster) => ({ - personID: x1.current_holder.id, - name: x1.current_holder.firstName, - avatar: - x1.current_holder && - x1.current_holder.avatar != null && - x1.current_holder.avatarName != null - ? `${x1.current_holder.avatar}/${x1.current_holder.avatarName}` + .filter((x: any) => x.current_holderId != null && x.isDirector) + .map((x0: PosMaster) => { + // Level 2 + const childLevel1 = [ + // Level 2: Root not director + ...posMasterRoot + .filter( + (x: any) => + x.orgRootId == x0.orgRootId && x.current_holderId != null && !x.isDirector, + ) + .map((x00: PosMaster) => ({ + level: 2, + personID: x00.current_holder ? x00.current_holder.id : null, + name: x00.current_holder + ? `${x00.current_holder.firstName} ${x00.current_holder.lastName}` : null, - positionName: x1.current_holder.position, - positionNum: x1.orgChild1.orgChild1ShortName + x1.posMasterNo, - positionNumInt: x1.posMasterNo, - departmentName: x1.orgChild1.orgChild1Name, - organizationId: x1.orgChild1.id, - children: posMasterChild2 - .filter((x: any) => x.current_holderId != null && x.child1Id == x1.orgChild1Id) - .map((x2: PosMaster) => ({ - personID: x2.current_holder.id, - name: x2.current_holder.firstName, - avatar: - x2.current_holder && - x2.current_holder.avatar != null && - x2.current_holder.avatarName != null - ? `${x2.current_holder.avatar}/${x2.current_holder.avatarName}` - : null, - positionName: x2.current_holder.position, - positionNum: x2.orgChild2.orgChild2ShortName + x2.posMasterNo, - positionNumInt: x2.posMasterNo, - departmentName: x2.orgChild2.orgChild2Name, - organizationId: x2.orgChild2.id, - children: posMasterChild3 - .filter((x: any) => x.current_holderId != null && x.child2Id == x2.orgChild2Id) - .map((x3: PosMaster) => ({ - personID: x3.current_holder.id, - name: x3.current_holder.firstName, - avatar: - x3.current_holder && - x3.current_holder.avatar != null && - x3.current_holder.avatarName != null - ? `${x3.current_holder.avatar}/${x3.current_holder.avatarName}` + avatar: + x00.current_holder && + x00.current_holder.avatar != null && + x00.current_holder.avatarName != null + ? `${x00.current_holder.avatar}/${x00.current_holder.avatarName}` + : null, + positionName: x00.current_holder ? x00.current_holder.position : null, + positionNum: x00.orgRoot.orgRootShortName + x00.posMasterNo, + positionNumInt: x00.posMasterNo, + departmentName: x00.orgRoot.orgRootName, + organizationId: x00.orgRoot.id, + children: [], + })), + // Level 2: Child 1 director + ...posMasterChild1 + .filter((x: any) => x.isDirector && x.orgRootId == x0.orgRootId) + .map((x1: PosMaster) => { + // Level 3 + const childLevel2 = [ + // Level 3: Child 1 not director + ...posMasterChild1 + .filter( + (x: any) => + x.orgChild1Id == x1.orgChild1Id && + !x.isDirector && + x.current_holderId != null, + ) + .map((x11: PosMaster) => { + return { + level: 3, + personID: x11.current_holder ? x11.current_holder.id : null, + name: x11.current_holder + ? `${x11.current_holder.firstName} ${x11.current_holder.lastName}` : null, - positionName: x3.current_holder.position, - positionNum: x3.orgChild3.orgChild3ShortName + x3.posMasterNo, - positionNumInt: x3.posMasterNo, - departmentName: x3.orgChild3.orgChild3Name, - organizationId: x3.orgChild3.id, - children: posMasterChild4 - .filter( - (x: any) => x.current_holderId != null && x.child3Id == x3.orgChild3Id, - ) - .map((x4: PosMaster) => ({ - personID: x4.current_holder.id, - name: x4.current_holder.firstName, - avatar: - x4.current_holder && - x4.current_holder.avatar != null && - x4.current_holder.avatarName != null - ? `${x4.current_holder.avatar}/${x4.current_holder.avatarName}` + avatar: + x11.current_holder && + x11.current_holder.avatar != null && + x11.current_holder.avatarName != null + ? `${x11.current_holder.avatar}/${x11.current_holder.avatarName}` + : null, + positionName: x11.current_holder ? x11.current_holder.position : null, + positionNum: x11.orgChild1.orgChild1ShortName + x11.posMasterNo, + positionNumInt: x11.posMasterNo, + departmentName: x11.orgChild1.orgChild1Name, + organizationId: x11.orgChild1.id, + children: [], + }; + }), + // Level 3: Child 2 director + ...posMasterChild2 + .filter((x: any) => x.isDirector && x.orgChild1Id == x1.orgChild1Id) + .map((x2: PosMaster) => { + const childLevel3 = [ + // Level 4: Child 2 not director + ...posMasterChild2 + .filter( + (x: any) => + !x.isDirector && + x.current_holderId != null && + x.orgChild1Id == x2.orgChild1Id, + ) + .map((x22: PosMaster) => ({ + level: 4, + personID: x22.current_holder ? x22.current_holder.id : null, + name: x22.current_holder + ? `${x22.current_holder.firstName} ${x22.current_holder.lastName}` : null, - positionName: x4.current_holder.position, - positionNum: x4.orgChild4.orgChild4ShortName + x4.posMasterNo, - positionNumInt: x4.posMasterNo, - departmentName: x4.orgChild4.orgChild4Name, - organizationId: x4.orgChild4.id, - })), - })), - })), - })), - })); + avatar: + x22.current_holder && + x22.current_holder.avatar != null && + x22.current_holder.avatarName != null + ? `${x22.current_holder.avatar}/${x22.current_holder.avatarName}` + : null, + positionName: x22.current_holder ? x22.current_holder.position : null, + positionNum: `${x22.orgChild2.orgChild2ShortName} ${x22.posMasterNo}`, + positionNumInt: x22.posMasterNo, + departmentName: x22.orgChild2.orgChild2Name, + organizationId: x22.orgChild2.id, + children: [], + })), + // Level 4: Child 3 director + ...posMasterChild3 + .filter((x: any) => x.isDirector && x.orgChild2Id == x2.orgChild2Id) + .map((x3: PosMaster) => { + const childLevel4 = [ + ...posMasterChild3 + .filter( + (x: any) => + !x.isDirector && + x.current_holderId != null && + x.orgChild2Id == x3.orgChild2Id, + ) + .map((x33: PosMaster) => ({ + level: 5, + personID: x33.current_holder ? x33.current_holder.id : null, + name: x33.current_holder + ? `${x33.current_holder.firstName} ${x33.current_holder.lastName}` + : null, + avatar: + x33.current_holder && + x33.current_holder.avatar != null && + x33.current_holder.avatarName != null + ? `${x33.current_holder.avatar}/${x33.current_holder.avatarName}` + : null, + positionName: x33.current_holder + ? x33.current_holder.position + : null, + positionNum: x33.orgChild3.orgChild3ShortName + x33.posMasterNo, + positionNumInt: x33.posMasterNo, + departmentName: x33.orgChild3.orgChild3Name, + organizationId: x33.orgChild3.id, + children: [], + })), + ...posMasterChild4 + .filter((x: any) => x.isDirector && x.orgChild3Id == x3.orgChild3Id) + .map((x4: PosMaster) => { + const childLevel5 = posMasterChild4 + .filter( + (x: any) => + !x.isDirector && + x.current_holderId != null && + x.orgChild3Id == x4.orgChild3Id, + ) + .map((x44: PosMaster) => ({ + level: 5, + personID: x44.current_holder ? x44.current_holder.id : null, + name: x44.current_holder + ? `${x44.current_holder.firstName} ${x44.current_holder.lastName}` + : null, + avatar: + x44.current_holder && + x44.current_holder.avatar != null && + x44.current_holder.avatarName != null + ? `${x44.current_holder.avatar}/${x44.current_holder.avatarName}` + : null, + positionName: x44.current_holder + ? x44.current_holder.position + : null, + positionNum: + x44.orgChild4.orgChild4ShortName + x44.posMasterNo, + positionNumInt: x44.posMasterNo, + departmentName: x44.orgChild4.orgChild4Name, + organizationId: x44.orgChild4.id, + children: [], + })); + + return { + level: 4, + personID: x4.current_holder ? x4.current_holder.id : null, + name: x4.current_holder + ? `${x4.current_holder.firstName} ${x4.current_holder.lastName}` + : null, + avatar: + x4.current_holder && + x4.current_holder.avatar != null && + x4.current_holder.avatarName != null + ? `${x4.current_holder.avatar}/${x4.current_holder.avatarName}` + : null, + positionName: x4.current_holder + ? x4.current_holder.position + : null, + positionNum: x4.orgChild4.orgChild4ShortName + x4.posMasterNo, + positionNumInt: x4.posMasterNo, + departmentName: x4.orgChild4.orgChild4Name, + organizationId: x4.orgChild4.id, + children: childLevel5, + }; + }), + ]; + + return { + level: 4, + personID: x3.current_holder ? x3.current_holder.id : null, + name: x3.current_holder + ? `${x3.current_holder.firstName} ${x3.current_holder.lastName}` + : null, + avatar: + x3.current_holder && + x3.current_holder.avatar != null && + x3.current_holder.avatarName != null + ? `${x3.current_holder.avatar}/${x3.current_holder.avatarName}` + : null, + positionName: x3.current_holder ? x3.current_holder.position : null, + positionNum: `${x3.orgChild3.orgChild3ShortName} ${x3.posMasterNo}`, + positionNumInt: x3.posMasterNo, + departmentName: x3.orgChild3.orgChild3Name, + organizationId: x3.orgChild3.id, + children: childLevel4, + }; + }), + ]; + + return { + level: 3, + personID: x2.current_holder ? x2.current_holder.id : null, + name: x2.current_holder + ? `${x2.current_holder.firstName} ${x2.current_holder.lastName}` + : null, + avatar: + x2.current_holder && + x2.current_holder.avatar != null && + x2.current_holder.avatarName != null + ? `${x2.current_holder.avatar}/${x2.current_holder.avatarName}` + : null, + positionName: x2.current_holder ? x2.current_holder.position : null, + positionNum: x2.orgChild2.orgChild2ShortName + x2.posMasterNo, + positionNumInt: x2.posMasterNo, + departmentName: x2.orgChild2.orgChild2Name, + organizationId: x2.orgChild2.id, + children: childLevel3, + }; + }), + ]; + + return { + level: 2, + personID: x1.current_holder ? x1.current_holder.id : null, + name: x1.current_holder + ? `${x1.current_holder.firstName} ${x1.current_holder.lastName}` + : null, + avatar: + x1.current_holder && + x1.current_holder.avatar != null && + x1.current_holder.avatarName != null + ? `${x1.current_holder.avatar}/${x1.current_holder.avatarName}` + : null, + positionName: x1.current_holder ? x1.current_holder.position : null, + positionNum: x1.orgChild1.orgChild1ShortName + x1.posMasterNo, + positionNumInt: x1.posMasterNo, + departmentName: x1.orgChild1.orgChild1Name, + organizationId: x1.orgChild1.id, + children: childLevel2, + }; + }), + ]; + + // Root Level 1 + return { + level: 1, + personID: x0.current_holder.id, + name: `${x0.current_holder.firstName} ${x0.current_holder.lastName}`, + avatar: + x0.current_holder && + x0.current_holder.avatar != null && + x0.current_holder.avatarName != null + ? `${x0.current_holder.avatar}/${x0.current_holder.avatarName}` + : null, + positionName: x0.current_holder.position, + positionNum: x0.orgRoot.orgRootShortName + x0.posMasterNo, + positionNumInt: x0.posMasterNo, + departmentName: x0.orgRoot.orgRootName, + organizationId: x0.orgRoot.id, + children: childLevel1, + }; + }); const formattedData_ = { personID: "", @@ -3656,7 +3846,7 @@ export class OrganizationController extends Controller { where: { orgRevisionId: data.id, orgChild1Id: IsNull(), - next_holderId: Not(IsNull()), + // next_holderId: Not(IsNull()), }, relations: ["next_holder", "orgRoot"], }); @@ -3665,7 +3855,7 @@ export class OrganizationController extends Controller { orgRevisionId: data.id, orgChild2Id: IsNull(), orgChild1Id: Not(IsNull()), - next_holderId: Not(IsNull()), + // next_holderId: Not(IsNull()), }, relations: ["next_holder", "orgChild1"], }); @@ -3674,7 +3864,7 @@ export class OrganizationController extends Controller { orgRevisionId: data.id, orgChild3Id: IsNull(), orgChild2Id: Not(IsNull()), - next_holderId: Not(IsNull()), + // next_holderId: Not(IsNull()), }, relations: ["next_holder", "orgChild2"], }); @@ -3683,7 +3873,7 @@ export class OrganizationController extends Controller { orgRevisionId: data.id, orgChild4Id: IsNull(), orgChild3Id: Not(IsNull()), - next_holderId: Not(IsNull()), + // next_holderId: Not(IsNull()), }, relations: ["next_holder", "orgChild3"], }); @@ -3691,92 +3881,274 @@ export class OrganizationController extends Controller { where: { orgRevisionId: data.id, orgChild4Id: Not(IsNull()), - next_holderId: Not(IsNull()), + // next_holderId: Not(IsNull()), }, relations: ["next_holder", "orgChild4"], }); let formattedData = posMasterRoot - .filter((x: any) => x.next_holderId != null) - .map((x0: PosMaster) => ({ - personID: x0.next_holder.id, - name: x0.next_holder.firstName, - avatar: - x0.next_holder && x0.next_holder.avatar != null && x0.next_holder.avatarName != null - ? `${x0.next_holder.avatar}/${x0.next_holder.avatarName}` - : null, - positionName: x0.next_holder.position, - positionNum: x0.orgRoot.orgRootShortName + x0.posMasterNo, - positionNumInt: x0.posMasterNo, - departmentName: x0.orgRoot.orgRootName, - organizationId: x0.orgRoot.id, - children: posMasterChild1 - .filter((x: any) => x.next_holderId != null && x.orgRootId == x0.orgRootId) - .map((x1: PosMaster) => ({ - personID: x1.next_holder.id, - name: x1.next_holder.firstName, - avatar: - x1.next_holder && x1.next_holder.avatar != null && x1.next_holder.avatarName != null - ? `${x1.next_holder.avatar}/${x1.next_holder.avatarName}` + .filter((x: any) => x.next_holderId != null && x.isDirector) + .map((x0: PosMaster) => { + // Level 2 + const childLevel1 = [ + // Level 2: Root not director + ...posMasterRoot + .filter( + (x: any) => x.orgRootId == x0.orgRootId && x.next_holderId != null && !x.isDirector, + ) + .map((x00: PosMaster) => ({ + level: 2, + personID: x00.next_holder ? x00.next_holder.id : null, + name: x00.next_holder + ? `${x00.next_holder.firstName} ${x00.next_holder.lastName}` : null, - positionName: x1.next_holder.position, - positionNum: x1.orgChild1.orgChild1ShortName + x1.posMasterNo, - positionNumInt: x1.posMasterNo, - departmentName: x1.orgChild1.orgChild1Name, - organizationId: x1.orgChild1.id, - children: posMasterChild2 - .filter((x: any) => x.next_holderId != null && x.child1Id == x1.orgChild1Id) - .map((x2: PosMaster) => ({ - personID: x2.next_holder.id, - name: x2.next_holder.firstName, - avatar: - x2.next_holder && - x2.next_holder.avatar != null && - x2.next_holder.avatarName != null - ? `${x2.next_holder.avatar}/${x2.next_holder.avatarName}` - : null, - positionName: x2.next_holder.position, - positionNum: x2.orgChild2.orgChild2ShortName + x2.posMasterNo, - positionNumInt: x2.posMasterNo, - departmentName: x2.orgChild2.orgChild2Name, - organizationId: x2.orgChild2.id, - children: posMasterChild3 - .filter((x: any) => x.next_holderId != null && x.child2Id == x2.orgChild2Id) - .map((x3: PosMaster) => ({ - personID: x3.next_holder.id, - name: x3.next_holder.firstName, - avatar: - x3.next_holder && - x3.next_holder.avatar != null && - x3.next_holder.avatarName != null - ? `${x3.next_holder.avatar}/${x3.next_holder.avatarName}` + avatar: + x00.next_holder && + x00.next_holder.avatar != null && + x00.next_holder.avatarName != null + ? `${x00.next_holder.avatar}/${x00.next_holder.avatarName}` + : null, + positionName: x00.next_holder ? x00.next_holder.position : null, + positionNum: x00.orgRoot.orgRootShortName + x00.posMasterNo, + positionNumInt: x00.posMasterNo, + departmentName: x00.orgRoot.orgRootName, + organizationId: x00.orgRoot.id, + children: [], + })), + // Level 2: Child 1 director + ...posMasterChild1 + .filter((x: any) => x.isDirector && x.orgRootId == x0.orgRootId) + .map((x1: PosMaster) => { + // Level 3 + const childLevel2 = [ + // Level 3: Child 1 not director + ...posMasterChild1 + .filter( + (x: any) => + x.orgChild1Id == x1.orgChild1Id && !x.isDirector && x.next_holderId != null, + ) + .map((x11: PosMaster) => { + return { + level: 3, + personID: x11.next_holder ? x11.next_holder.id : null, + name: x11.next_holder + ? `${x11.next_holder.firstName} ${x11.next_holder.lastName}` : null, - positionName: x3.next_holder.position, - positionNum: x3.orgChild3.orgChild3ShortName + x3.posMasterNo, - positionNumInt: x3.posMasterNo, - departmentName: x3.orgChild3.orgChild3Name, - organizationId: x3.orgChild3.id, - children: posMasterChild4 - .filter((x: any) => x.next_holderId != null && x.child3Id == x3.orgChild3Id) - .map((x4: PosMaster) => ({ - personID: x4.next_holder.id, - name: x4.next_holder.firstName, - avatar: - x4.next_holder && - x4.next_holder.avatar != null && - x4.next_holder.avatarName != null - ? `${x4.next_holder.avatar}/${x4.next_holder.avatarName}` + avatar: + x11.next_holder && + x11.next_holder.avatar != null && + x11.next_holder.avatarName != null + ? `${x11.next_holder.avatar}/${x11.next_holder.avatarName}` + : null, + positionName: x11.next_holder ? x11.next_holder.position : null, + positionNum: x11.orgChild1.orgChild1ShortName + x11.posMasterNo, + positionNumInt: x11.posMasterNo, + departmentName: x11.orgChild1.orgChild1Name, + organizationId: x11.orgChild1.id, + children: [], + }; + }), + // Level 3: Child 2 director + ...posMasterChild2 + .filter((x: any) => x.isDirector && x.orgChild1Id == x1.orgChild1Id) + .map((x2: PosMaster) => { + const childLevel3 = [ + // Level 4: Child 2 not director + ...posMasterChild2 + .filter( + (x: any) => + !x.isDirector && + x.next_holderId != null && + x.orgChild1Id == x2.orgChild1Id, + ) + .map((x22: PosMaster) => ({ + level: 4, + personID: x22.next_holder ? x22.next_holder.id : null, + name: x22.next_holder + ? `${x22.next_holder.firstName} ${x22.next_holder.lastName}` : null, - positionName: x4.next_holder.position, - positionNum: x4.orgChild4.orgChild4ShortName + x4.posMasterNo, - positionNumInt: x4.posMasterNo, - departmentName: x4.orgChild4.orgChild4Name, - organizationId: x4.orgChild4.id, - })), - })), - })), - })), - })); + avatar: + x22.next_holder && + x22.next_holder.avatar != null && + x22.next_holder.avatarName != null + ? `${x22.next_holder.avatar}/${x22.next_holder.avatarName}` + : null, + positionName: x22.next_holder ? x22.next_holder.position : null, + positionNum: `${x22.orgChild2.orgChild2ShortName} ${x22.posMasterNo}`, + positionNumInt: x22.posMasterNo, + departmentName: x22.orgChild2.orgChild2Name, + organizationId: x22.orgChild2.id, + children: [], + })), + // Level 4: Child 3 director + ...posMasterChild3 + .filter((x: any) => x.isDirector && x.orgChild2Id == x2.orgChild2Id) + .map((x3: PosMaster) => { + const childLevel4 = [ + ...posMasterChild3 + .filter( + (x: any) => + !x.isDirector && + x.next_holderId != null && + x.orgChild2Id == x3.orgChild2Id, + ) + .map((x33: PosMaster) => ({ + level: 5, + personID: x33.next_holder ? x33.next_holder.id : null, + name: x33.next_holder + ? `${x33.next_holder.firstName} ${x33.next_holder.lastName}` + : null, + avatar: + x33.next_holder && + x33.next_holder.avatar != null && + x33.next_holder.avatarName != null + ? `${x33.next_holder.avatar}/${x33.next_holder.avatarName}` + : null, + positionName: x33.next_holder ? x33.next_holder.position : null, + positionNum: x33.orgChild3.orgChild3ShortName + x33.posMasterNo, + positionNumInt: x33.posMasterNo, + departmentName: x33.orgChild3.orgChild3Name, + organizationId: x33.orgChild3.id, + children: [], + })), + ...posMasterChild4 + .filter((x: any) => x.isDirector && x.orgChild3Id == x3.orgChild3Id) + .map((x4: PosMaster) => { + const childLevel5 = posMasterChild4 + .filter( + (x: any) => + !x.isDirector && + x.next_holderId != null && + x.orgChild3Id == x4.orgChild3Id, + ) + .map((x44: PosMaster) => ({ + level: 5, + personID: x44.next_holder ? x44.next_holder.id : null, + name: x44.next_holder + ? `${x44.next_holder.firstName} ${x44.next_holder.lastName}` + : null, + avatar: + x44.next_holder && + x44.next_holder.avatar != null && + x44.next_holder.avatarName != null + ? `${x44.next_holder.avatar}/${x44.next_holder.avatarName}` + : null, + positionName: x44.next_holder + ? x44.next_holder.position + : null, + positionNum: + x44.orgChild4.orgChild4ShortName + x44.posMasterNo, + positionNumInt: x44.posMasterNo, + departmentName: x44.orgChild4.orgChild4Name, + organizationId: x44.orgChild4.id, + children: [], + })); + + return { + level: 4, + personID: x4.next_holder ? x4.next_holder.id : null, + name: x4.next_holder + ? `${x4.next_holder.firstName} ${x4.next_holder.lastName}` + : null, + avatar: + x4.next_holder && + x4.next_holder.avatar != null && + x4.next_holder.avatarName != null + ? `${x4.next_holder.avatar}/${x4.next_holder.avatarName}` + : null, + positionName: x4.next_holder ? x4.next_holder.position : null, + positionNum: x4.orgChild4.orgChild4ShortName + x4.posMasterNo, + positionNumInt: x4.posMasterNo, + departmentName: x4.orgChild4.orgChild4Name, + organizationId: x4.orgChild4.id, + children: childLevel5, + }; + }), + ]; + + return { + level: 4, + personID: x3.next_holder ? x3.next_holder.id : null, + name: x3.next_holder + ? `${x3.next_holder.firstName} ${x3.next_holder.lastName}` + : null, + avatar: + x3.next_holder && + x3.next_holder.avatar != null && + x3.next_holder.avatarName != null + ? `${x3.next_holder.avatar}/${x3.next_holder.avatarName}` + : null, + positionName: x3.next_holder ? x3.next_holder.position : null, + positionNum: `${x3.orgChild3.orgChild3ShortName} ${x3.posMasterNo}`, + positionNumInt: x3.posMasterNo, + departmentName: x3.orgChild3.orgChild3Name, + organizationId: x3.orgChild3.id, + children: childLevel4, + }; + }), + ]; + + return { + level: 3, + personID: x2.next_holder ? x2.next_holder.id : null, + name: x2.next_holder + ? `${x2.next_holder.firstName} ${x2.next_holder.lastName}` + : null, + avatar: + x2.next_holder && + x2.next_holder.avatar != null && + x2.next_holder.avatarName != null + ? `${x2.next_holder.avatar}/${x2.next_holder.avatarName}` + : null, + positionName: x2.next_holder ? x2.next_holder.position : null, + positionNum: x2.orgChild2.orgChild2ShortName + x2.posMasterNo, + positionNumInt: x2.posMasterNo, + departmentName: x2.orgChild2.orgChild2Name, + organizationId: x2.orgChild2.id, + children: childLevel3, + }; + }), + ]; + + return { + level: 2, + personID: x1.next_holder ? x1.next_holder.id : null, + name: x1.next_holder + ? `${x1.next_holder.firstName} ${x1.next_holder.lastName}` + : null, + avatar: + x1.next_holder && + x1.next_holder.avatar != null && + x1.next_holder.avatarName != null + ? `${x1.next_holder.avatar}/${x1.next_holder.avatarName}` + : null, + positionName: x1.next_holder ? x1.next_holder.position : null, + positionNum: x1.orgChild1.orgChild1ShortName + x1.posMasterNo, + positionNumInt: x1.posMasterNo, + departmentName: x1.orgChild1.orgChild1Name, + organizationId: x1.orgChild1.id, + children: childLevel2, + }; + }), + ]; + + // Root Level 1 + return { + level: 1, + personID: x0.next_holder.id, + name: `${x0.next_holder.firstName} ${x0.next_holder.lastName}`, + avatar: + x0.next_holder && x0.next_holder.avatar != null && x0.next_holder.avatarName != null + ? `${x0.next_holder.avatar}/${x0.next_holder.avatarName}` + : null, + positionName: x0.next_holder.position, + positionNum: x0.orgRoot.orgRootShortName + x0.posMasterNo, + positionNumInt: x0.posMasterNo, + departmentName: x0.orgRoot.orgRootName, + organizationId: x0.orgRoot.id, + children: childLevel1, + }; + }); const formattedData_ = { personID: "", @@ -5373,7 +5745,11 @@ export class OrganizationController extends Controller { posMaster: await Promise.all( orgRoot.posMasters .filter( - (x) => x.orgChild1Id == null && x.current_holderId != null && x.posMasterOrder <= 3 && x.isDirector === true, + (x) => + x.orgChild1Id == null && + x.current_holderId != null && + x.posMasterOrder <= 3 && + x.isDirector === true, ) .map(async (x) => ({ posmasterId: x.id, @@ -5413,7 +5789,7 @@ export class OrganizationController extends Controller { x.orgChild2Id == null && x.current_holderId != null && x.posMasterOrder <= 3 && - x.isDirector === true + x.isDirector === true, ) .map(async (x) => ({ posmasterId: x.id, @@ -5453,7 +5829,7 @@ export class OrganizationController extends Controller { (x) => x.orgChild3Id == null && x.current_holderId != null && - x.posMasterOrder <= 3 && + x.posMasterOrder <= 3 && x.isDirector === true, ) .map(async (x) => ({ @@ -5494,7 +5870,7 @@ export class OrganizationController extends Controller { (x) => x.orgChild4Id == null && x.current_holderId != null && - x.posMasterOrder <= 3 && + x.posMasterOrder <= 3 && x.isDirector === true, ) .map(async (x) => ({ @@ -5532,7 +5908,10 @@ export class OrganizationController extends Controller { posMaster: await Promise.all( orgChild4.posMasters .filter( - (x) => x.current_holderId != null && x.posMasterOrder <= 3 && x.isDirector === true, + (x) => + x.current_holderId != null && + x.posMasterOrder <= 3 && + x.isDirector === true, ) .map(async (x) => ({ posmasterId: x.id,