fix bug & org chart query

This commit is contained in:
Warunee Tamkoo 2024-11-08 16:57:40 +07:00
parent 52ae434f02
commit 7378e86244
2 changed files with 558 additions and 180 deletions

View file

@ -11,7 +11,6 @@ import { AppDataSource } from "./database/data-source";
import { RegisterRoutes } from "./routes"; import { RegisterRoutes } from "./routes";
import { OrganizationController } from "./controllers/OrganizationController"; import { OrganizationController } from "./controllers/OrganizationController";
import logMiddleware from "./middlewares/logs"; import logMiddleware from "./middlewares/logs";
import { run } from "node:test";
import { CommandController } from "./controllers/CommandController"; import { CommandController } from "./controllers/CommandController";
async function main() { async function main() {

View file

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