From 39a07482cddb311b9081e706269e97611191b45a Mon Sep 17 00:00:00 2001 From: Adisak Date: Thu, 5 Feb 2026 11:23:38 +0700 Subject: [PATCH] add api find dna by keycloak --- src/controllers/OrganizationController.ts | 1603 +++++++++++---------- 1 file changed, 836 insertions(+), 767 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index ad1f71d5..f19be17b 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -280,6 +280,75 @@ export class OrganizationController extends Controller { return new HttpSuccess(requestBody); } + /** + * API สร้างแบบร่างโครงสร้าง + * + * @summary ORG_022 - สร้างโครงสร้างใหม่ #23 + * + */ + @Post("finddna-by-keycloak/{keycloakId}") + async FindDnaOrgByKeycloakId( + @Path() keycloakId: string + ) { + + let reply: any; + + const profileByKeycloak: any = await this.profileRepo.findOne({ + where: { keycloak: keycloakId }, + select: ["id", "keycloak"] + }) + + const orgRevision = await this.orgRevisionRepository.findOne({ + select: ["id"], + where: { + orgRevisionIsDraft: false, + orgRevisionIsCurrent: true, + }, + }); + + const posMaster = await AppDataSource.getRepository(PosMaster) + .createQueryBuilder("pos") + .leftJoin("pos.orgRoot", "orgRoot") + .leftJoin("pos.orgChild1", "orgChild1") + .leftJoin("pos.orgChild2", "orgChild2") + .leftJoin("pos.orgChild3", "orgChild3") + .leftJoin("pos.orgChild4", "orgChild4") + .where("pos.current_holderId = :holderId", { + holderId: profileByKeycloak.id, + }) + .andWhere("pos.orgRevisionId = :revId", { + revId: orgRevision?.id, + }) + .select([ + "pos.id", + "orgRoot.ancestorDNA as rootDnaId", + "orgChild1.ancestorDNA as child1DnaId", + "orgChild2.ancestorDNA as child2DnaId", + "orgChild3.ancestorDNA as child3DnaId", + "orgChild4.ancestorDNA as child4DnaId", + ]) + .getRawOne(); + + if (!posMaster) { + reply = { + rootDnaId: null, + child1DnaId: null, + child2DnaId: null, + child3DnaId: null, + child4DnaId: null, + }; + } else { + reply = { + rootDnaId: posMaster.rootDnaId, + child1DnaId: posMaster.child1DnaId, + child2DnaId: posMaster.child2DnaId, + child3DnaId: posMaster.child3DnaId, + child4DnaId: posMaster.child4DnaId, + }; + } + return new HttpSuccess(reply); + } + /** * API เช็คสถานะโครงสร้างว่าส่งคนไปออกคำสั่งหรือไม่ * @@ -381,157 +450,157 @@ export class OrganizationController extends Controller { const orgChild1Data = orgRootIds && orgRootIds.length > 0 ? await AppDataSource.getRepository(OrgChild1) - .createQueryBuilder("orgChild1") - .where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds }) - // .andWhere( - // _data.child1 != undefined && _data.child1 != null - // ? _data.child1[0] != null - // ? `orgChild1.id IN (:...node)` - // : `orgChild1.id is null` - // : "1=1", - // { - // node: _data.child1, - // }, - // ) - .select([ - "orgChild1.id", - "orgChild1.isOfficer", - "orgChild1.isInformation", - "orgChild1.orgChild1Name", - "orgChild1.orgChild1ShortName", - "orgChild1.orgChild1Code", - "orgChild1.orgChild1Order", - "orgChild1.orgChild1PhoneEx", - "orgChild1.orgChild1PhoneIn", - "orgChild1.orgChild1Fax", - "orgChild1.orgRootId", - "orgChild1.orgChild1Rank", - "orgChild1.orgChild1RankSub", - "orgChild1.DEPARTMENT_CODE", - "orgChild1.DIVISION_CODE", - "orgChild1.SECTION_CODE", - "orgChild1.JOB_CODE", - "orgChild1.responsibility", - ]) - .orderBy("orgChild1.orgChild1Order", "ASC") - .getMany() + .createQueryBuilder("orgChild1") + .where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds }) + // .andWhere( + // _data.child1 != undefined && _data.child1 != null + // ? _data.child1[0] != null + // ? `orgChild1.id IN (:...node)` + // : `orgChild1.id is null` + // : "1=1", + // { + // node: _data.child1, + // }, + // ) + .select([ + "orgChild1.id", + "orgChild1.isOfficer", + "orgChild1.isInformation", + "orgChild1.orgChild1Name", + "orgChild1.orgChild1ShortName", + "orgChild1.orgChild1Code", + "orgChild1.orgChild1Order", + "orgChild1.orgChild1PhoneEx", + "orgChild1.orgChild1PhoneIn", + "orgChild1.orgChild1Fax", + "orgChild1.orgRootId", + "orgChild1.orgChild1Rank", + "orgChild1.orgChild1RankSub", + "orgChild1.DEPARTMENT_CODE", + "orgChild1.DIVISION_CODE", + "orgChild1.SECTION_CODE", + "orgChild1.JOB_CODE", + "orgChild1.responsibility", + ]) + .orderBy("orgChild1.orgChild1Order", "ASC") + .getMany() : []; const orgChild1Ids = orgChild1Data.map((orgChild1) => orgChild1.id) || null; const orgChild2Data = orgChild1Ids && orgChild1Ids.length > 0 ? await AppDataSource.getRepository(OrgChild2) - .createQueryBuilder("orgChild2") - .where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids }) - // .andWhere( - // _data.child2 != undefined && _data.child2 != null - // ? _data.child2[0] != null - // ? `orgChild2.id IN (:...node)` - // : `orgChild2.id is null` - // : "1=1", - // { - // node: _data.child2, - // }, - // ) - .select([ - "orgChild2.id", - "orgChild2.orgChild2Name", - "orgChild2.orgChild2ShortName", - "orgChild2.orgChild2Code", - "orgChild2.orgChild2Order", - "orgChild2.orgChild2PhoneEx", - "orgChild2.orgChild2PhoneIn", - "orgChild2.orgChild2Fax", - "orgChild2.orgRootId", - "orgChild2.orgChild2Rank", - "orgChild2.orgChild2RankSub", - "orgChild2.DEPARTMENT_CODE", - "orgChild2.DIVISION_CODE", - "orgChild2.SECTION_CODE", - "orgChild2.JOB_CODE", - "orgChild2.orgChild1Id", - "orgChild2.responsibility", - ]) - .orderBy("orgChild2.orgChild2Order", "ASC") - .getMany() + .createQueryBuilder("orgChild2") + .where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids }) + // .andWhere( + // _data.child2 != undefined && _data.child2 != null + // ? _data.child2[0] != null + // ? `orgChild2.id IN (:...node)` + // : `orgChild2.id is null` + // : "1=1", + // { + // node: _data.child2, + // }, + // ) + .select([ + "orgChild2.id", + "orgChild2.orgChild2Name", + "orgChild2.orgChild2ShortName", + "orgChild2.orgChild2Code", + "orgChild2.orgChild2Order", + "orgChild2.orgChild2PhoneEx", + "orgChild2.orgChild2PhoneIn", + "orgChild2.orgChild2Fax", + "orgChild2.orgRootId", + "orgChild2.orgChild2Rank", + "orgChild2.orgChild2RankSub", + "orgChild2.DEPARTMENT_CODE", + "orgChild2.DIVISION_CODE", + "orgChild2.SECTION_CODE", + "orgChild2.JOB_CODE", + "orgChild2.orgChild1Id", + "orgChild2.responsibility", + ]) + .orderBy("orgChild2.orgChild2Order", "ASC") + .getMany() : []; const orgChild2Ids = orgChild2Data.map((orgChild2) => orgChild2.id) || null; const orgChild3Data = orgChild2Ids && orgChild2Ids.length > 0 ? await AppDataSource.getRepository(OrgChild3) - .createQueryBuilder("orgChild3") - .where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids }) - // .andWhere( - // _data.child3 != undefined && _data.child3 != null - // ? _data.child3[0] != null - // ? `orgChild3.id IN (:...node)` - // : `orgChild3.id is null` - // : "1=1", - // { - // node: _data.child3, - // }, - // ) - .select([ - "orgChild3.id", - "orgChild3.orgChild3Name", - "orgChild3.orgChild3ShortName", - "orgChild3.orgChild3Code", - "orgChild3.orgChild3Order", - "orgChild3.orgChild3PhoneEx", - "orgChild3.orgChild3PhoneIn", - "orgChild3.orgChild3Fax", - "orgChild3.orgRootId", - "orgChild3.orgChild3Rank", - "orgChild3.orgChild3RankSub", - "orgChild3.DEPARTMENT_CODE", - "orgChild3.DIVISION_CODE", - "orgChild3.SECTION_CODE", - "orgChild3.JOB_CODE", - "orgChild3.orgChild2Id", - "orgChild3.responsibility", - ]) - .orderBy("orgChild3.orgChild3Order", "ASC") - .getMany() + .createQueryBuilder("orgChild3") + .where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids }) + // .andWhere( + // _data.child3 != undefined && _data.child3 != null + // ? _data.child3[0] != null + // ? `orgChild3.id IN (:...node)` + // : `orgChild3.id is null` + // : "1=1", + // { + // node: _data.child3, + // }, + // ) + .select([ + "orgChild3.id", + "orgChild3.orgChild3Name", + "orgChild3.orgChild3ShortName", + "orgChild3.orgChild3Code", + "orgChild3.orgChild3Order", + "orgChild3.orgChild3PhoneEx", + "orgChild3.orgChild3PhoneIn", + "orgChild3.orgChild3Fax", + "orgChild3.orgRootId", + "orgChild3.orgChild3Rank", + "orgChild3.orgChild3RankSub", + "orgChild3.DEPARTMENT_CODE", + "orgChild3.DIVISION_CODE", + "orgChild3.SECTION_CODE", + "orgChild3.JOB_CODE", + "orgChild3.orgChild2Id", + "orgChild3.responsibility", + ]) + .orderBy("orgChild3.orgChild3Order", "ASC") + .getMany() : []; const orgChild3Ids = orgChild3Data.map((orgChild3) => orgChild3.id) || null; const orgChild4Data = orgChild3Ids && orgChild3Ids.length > 0 ? await AppDataSource.getRepository(OrgChild4) - .createQueryBuilder("orgChild4") - .where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids }) - // .andWhere( - // _data.child4 != undefined && _data.child4 != null - // ? _data.child4[0] != null - // ? `orgChild4.id IN (:...node)` - // : `orgChild4.id is null` - // : "1=1", - // { - // node: _data.child4, - // }, - // ) - .select([ - "orgChild4.id", - "orgChild4.orgChild4Name", - "orgChild4.orgChild4ShortName", - "orgChild4.orgChild4Code", - "orgChild4.orgChild4Order", - "orgChild4.orgChild4PhoneEx", - "orgChild4.orgChild4PhoneIn", - "orgChild4.orgChild4Fax", - "orgChild4.orgRootId", - "orgChild4.orgChild4Rank", - "orgChild4.orgChild4RankSub", - "orgChild4.DEPARTMENT_CODE", - "orgChild4.DIVISION_CODE", - "orgChild4.SECTION_CODE", - "orgChild4.JOB_CODE", - "orgChild4.orgChild3Id", - "orgChild4.responsibility", - ]) - .orderBy("orgChild4.orgChild4Order", "ASC") - .getMany() + .createQueryBuilder("orgChild4") + .where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids }) + // .andWhere( + // _data.child4 != undefined && _data.child4 != null + // ? _data.child4[0] != null + // ? `orgChild4.id IN (:...node)` + // : `orgChild4.id is null` + // : "1=1", + // { + // node: _data.child4, + // }, + // ) + .select([ + "orgChild4.id", + "orgChild4.orgChild4Name", + "orgChild4.orgChild4ShortName", + "orgChild4.orgChild4Code", + "orgChild4.orgChild4Order", + "orgChild4.orgChild4PhoneEx", + "orgChild4.orgChild4PhoneIn", + "orgChild4.orgChild4Fax", + "orgChild4.orgRootId", + "orgChild4.orgChild4Rank", + "orgChild4.orgChild4RankSub", + "orgChild4.DEPARTMENT_CODE", + "orgChild4.DIVISION_CODE", + "orgChild4.SECTION_CODE", + "orgChild4.JOB_CODE", + "orgChild4.orgChild3Id", + "orgChild4.responsibility", + ]) + .orderBy("orgChild4.orgChild4Order", "ASC") + .getMany() : []; const formattedData = await Promise.all( @@ -1184,13 +1253,13 @@ export class OrganizationController extends Controller { where: orgRevision.orgRevisionIsCurrent && !orgRevision.orgRevisionIsDraft ? { - orgRevisionId: id, - current_holderId: profile.id, - } + orgRevisionId: id, + current_holderId: profile.id, + } : { - orgRevisionId: id, - next_holderId: profile.id, - }, + orgRevisionId: id, + next_holderId: profile.id, + }, }); if (!posMaster) return new HttpSuccess([]); @@ -1667,161 +1736,161 @@ export class OrganizationController extends Controller { const orgChild1Data = orgRootIds && orgRootIds.length > 0 ? await AppDataSource.getRepository(OrgChild1) - .createQueryBuilder("orgChild1") - .where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds }) - .andWhere( - _data.child1 !== undefined && _data.child1 !== null - ? _data.child1[0] !== null - ? `orgChild1.id IN (:...node)` - : `orgChild1.id is null` - : "1=1", - { - node: _data.child1, - }, - ) - .select([ - "orgChild1.id", - "orgChild1.misId", - "orgChild1.isOfficer", - "orgChild1.isInformation", - "orgChild1.orgChild1Name", - "orgChild1.orgChild1ShortName", - "orgChild1.orgChild1Code", - "orgChild1.orgChild1Order", - "orgChild1.orgChild1PhoneEx", - "orgChild1.orgChild1PhoneIn", - "orgChild1.orgChild1Fax", - "orgChild1.orgRootId", - "orgChild1.orgChild1Rank", - "orgChild1.orgChild1RankSub", - "orgChild1.DEPARTMENT_CODE", - "orgChild1.DIVISION_CODE", - "orgChild1.SECTION_CODE", - "orgChild1.JOB_CODE", - "orgChild1.responsibility", - ]) - .orderBy("orgChild1.orgChild1Order", "ASC") - .getMany() + .createQueryBuilder("orgChild1") + .where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds }) + .andWhere( + _data.child1 !== undefined && _data.child1 !== null + ? _data.child1[0] !== null + ? `orgChild1.id IN (:...node)` + : `orgChild1.id is null` + : "1=1", + { + node: _data.child1, + }, + ) + .select([ + "orgChild1.id", + "orgChild1.misId", + "orgChild1.isOfficer", + "orgChild1.isInformation", + "orgChild1.orgChild1Name", + "orgChild1.orgChild1ShortName", + "orgChild1.orgChild1Code", + "orgChild1.orgChild1Order", + "orgChild1.orgChild1PhoneEx", + "orgChild1.orgChild1PhoneIn", + "orgChild1.orgChild1Fax", + "orgChild1.orgRootId", + "orgChild1.orgChild1Rank", + "orgChild1.orgChild1RankSub", + "orgChild1.DEPARTMENT_CODE", + "orgChild1.DIVISION_CODE", + "orgChild1.SECTION_CODE", + "orgChild1.JOB_CODE", + "orgChild1.responsibility", + ]) + .orderBy("orgChild1.orgChild1Order", "ASC") + .getMany() : []; const orgChild1Ids = orgChild1Data.map((orgChild1) => orgChild1.id) || null; const orgChild2Data = orgChild1Ids && orgChild1Ids.length > 0 ? await AppDataSource.getRepository(OrgChild2) - .createQueryBuilder("orgChild2") - .where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids }) - .andWhere( - _data.child2 !== undefined && _data.child2 !== null - ? _data.child2[0] !== null - ? `orgChild2.id IN (:...node)` - : `orgChild2.id is null` - : "1=1", - { - node: _data.child2, - }, - ) - .select([ - "orgChild2.id", - "orgChild2.misId", - "orgChild2.orgChild2Name", - "orgChild2.orgChild2ShortName", - "orgChild2.orgChild2Code", - "orgChild2.orgChild2Order", - "orgChild2.orgChild2PhoneEx", - "orgChild2.orgChild2PhoneIn", - "orgChild2.orgChild2Fax", - "orgChild2.orgRootId", - "orgChild2.orgChild2Rank", - "orgChild2.orgChild2RankSub", - "orgChild2.DEPARTMENT_CODE", - "orgChild2.DIVISION_CODE", - "orgChild2.SECTION_CODE", - "orgChild2.JOB_CODE", - "orgChild2.orgChild1Id", - "orgChild2.responsibility", - ]) - .orderBy("orgChild2.orgChild2Order", "ASC") - .getMany() + .createQueryBuilder("orgChild2") + .where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids }) + .andWhere( + _data.child2 !== undefined && _data.child2 !== null + ? _data.child2[0] !== null + ? `orgChild2.id IN (:...node)` + : `orgChild2.id is null` + : "1=1", + { + node: _data.child2, + }, + ) + .select([ + "orgChild2.id", + "orgChild2.misId", + "orgChild2.orgChild2Name", + "orgChild2.orgChild2ShortName", + "orgChild2.orgChild2Code", + "orgChild2.orgChild2Order", + "orgChild2.orgChild2PhoneEx", + "orgChild2.orgChild2PhoneIn", + "orgChild2.orgChild2Fax", + "orgChild2.orgRootId", + "orgChild2.orgChild2Rank", + "orgChild2.orgChild2RankSub", + "orgChild2.DEPARTMENT_CODE", + "orgChild2.DIVISION_CODE", + "orgChild2.SECTION_CODE", + "orgChild2.JOB_CODE", + "orgChild2.orgChild1Id", + "orgChild2.responsibility", + ]) + .orderBy("orgChild2.orgChild2Order", "ASC") + .getMany() : []; const orgChild2Ids = orgChild2Data.map((orgChild2) => orgChild2.id) || null; const orgChild3Data = orgChild2Ids && orgChild2Ids.length > 0 ? await AppDataSource.getRepository(OrgChild3) - .createQueryBuilder("orgChild3") - .where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids }) - .andWhere( - _data.child3 !== undefined && _data.child3 !== null - ? _data.child3[0] !== null - ? `orgChild3.id IN (:...node)` - : `orgChild3.id is null` - : "1=1", - { - node: _data.child3, - }, - ) - .select([ - "orgChild3.id", - "orgChild3.misId", - "orgChild3.orgChild3Name", - "orgChild3.orgChild3ShortName", - "orgChild3.orgChild3Code", - "orgChild3.orgChild3Order", - "orgChild3.orgChild3PhoneEx", - "orgChild3.orgChild3PhoneIn", - "orgChild3.orgChild3Fax", - "orgChild3.orgRootId", - "orgChild3.orgChild3Rank", - "orgChild3.orgChild3RankSub", - "orgChild3.DEPARTMENT_CODE", - "orgChild3.DIVISION_CODE", - "orgChild3.SECTION_CODE", - "orgChild3.JOB_CODE", - "orgChild3.orgChild2Id", - "orgChild3.responsibility", - ]) - .orderBy("orgChild3.orgChild3Order", "ASC") - .getMany() + .createQueryBuilder("orgChild3") + .where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids }) + .andWhere( + _data.child3 !== undefined && _data.child3 !== null + ? _data.child3[0] !== null + ? `orgChild3.id IN (:...node)` + : `orgChild3.id is null` + : "1=1", + { + node: _data.child3, + }, + ) + .select([ + "orgChild3.id", + "orgChild3.misId", + "orgChild3.orgChild3Name", + "orgChild3.orgChild3ShortName", + "orgChild3.orgChild3Code", + "orgChild3.orgChild3Order", + "orgChild3.orgChild3PhoneEx", + "orgChild3.orgChild3PhoneIn", + "orgChild3.orgChild3Fax", + "orgChild3.orgRootId", + "orgChild3.orgChild3Rank", + "orgChild3.orgChild3RankSub", + "orgChild3.DEPARTMENT_CODE", + "orgChild3.DIVISION_CODE", + "orgChild3.SECTION_CODE", + "orgChild3.JOB_CODE", + "orgChild3.orgChild2Id", + "orgChild3.responsibility", + ]) + .orderBy("orgChild3.orgChild3Order", "ASC") + .getMany() : []; const orgChild3Ids = orgChild3Data.map((orgChild3) => orgChild3.id) || null; const orgChild4Data = orgChild3Ids && orgChild3Ids.length > 0 ? await AppDataSource.getRepository(OrgChild4) - .createQueryBuilder("orgChild4") - .where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids }) - .andWhere( - _data.child4 !== undefined && _data.child4 !== null - ? _data.child4[0] !== null - ? `orgChild4.id IN (:...node)` - : `orgChild4.id is null` - : "1=1", - { - node: _data.child4, - }, - ) - .select([ - "orgChild4.id", - "orgChild4.misId", - "orgChild4.orgChild4Name", - "orgChild4.orgChild4ShortName", - "orgChild4.orgChild4Code", - "orgChild4.orgChild4Order", - "orgChild4.orgChild4PhoneEx", - "orgChild4.orgChild4PhoneIn", - "orgChild4.orgChild4Fax", - "orgChild4.orgRootId", - "orgChild4.orgChild4Rank", - "orgChild4.orgChild4RankSub", - "orgChild4.DEPARTMENT_CODE", - "orgChild4.DIVISION_CODE", - "orgChild4.SECTION_CODE", - "orgChild4.JOB_CODE", - "orgChild4.orgChild3Id", - "orgChild4.responsibility", - ]) - .orderBy("orgChild4.orgChild4Order", "ASC") - .getMany() + .createQueryBuilder("orgChild4") + .where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids }) + .andWhere( + _data.child4 !== undefined && _data.child4 !== null + ? _data.child4[0] !== null + ? `orgChild4.id IN (:...node)` + : `orgChild4.id is null` + : "1=1", + { + node: _data.child4, + }, + ) + .select([ + "orgChild4.id", + "orgChild4.misId", + "orgChild4.orgChild4Name", + "orgChild4.orgChild4ShortName", + "orgChild4.orgChild4Code", + "orgChild4.orgChild4Order", + "orgChild4.orgChild4PhoneEx", + "orgChild4.orgChild4PhoneIn", + "orgChild4.orgChild4Fax", + "orgChild4.orgRootId", + "orgChild4.orgChild4Rank", + "orgChild4.orgChild4RankSub", + "orgChild4.DEPARTMENT_CODE", + "orgChild4.DIVISION_CODE", + "orgChild4.SECTION_CODE", + "orgChild4.JOB_CODE", + "orgChild4.orgChild3Id", + "orgChild4.responsibility", + ]) + .orderBy("orgChild4.orgChild4Order", "ASC") + .getMany() : []; const formattedData = await Promise.all( @@ -3373,18 +3442,18 @@ export class OrganizationController extends Controller { const formattedData_ = rootId === "root" ? [ - { - personID: "", - name: "", - avatar: "", - positionName: "", - positionNum: "", - positionNumInt: null, - departmentName: data.orgRevisionName, - organizationId: data.id, - children: formattedData, - }, - ] + { + personID: "", + name: "", + avatar: "", + positionName: "", + positionNum: "", + positionNumInt: null, + departmentName: data.orgRevisionName, + organizationId: data.id, + children: formattedData, + }, + ] : formattedData; return new HttpSuccess(formattedData_); } @@ -3424,17 +3493,17 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgRevisionId: data.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgRevisionId: data.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgRevisionId: data.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgRevisionId: data.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: await this.posMasterRepository.count({ // where: { // orgRevisionId: data.id, @@ -3462,19 +3531,19 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgRevisionId: data.id, - orgRootId: orgRoot.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgRevisionId: data.id, + orgRootId: orgRoot.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgRevisionId: data.id, - orgRootId: orgRoot.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgRevisionId: data.id, + orgRootId: orgRoot.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: await this.posMasterRepository.count({ // where: { // orgRevisionId: data.id, @@ -3507,21 +3576,21 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgRevisionId: data.id, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgRevisionId: data.id, + orgRootId: orgRoot.id, + orgChild1Id: orgChild1.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgRevisionId: data.id, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgRevisionId: data.id, + orgRootId: orgRoot.id, + orgChild1Id: orgChild1.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: await this.posMasterRepository.count({ // where: { // orgRevisionId: data.id, @@ -3557,23 +3626,23 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgRevisionId: data.id, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgRevisionId: data.id, + orgRootId: orgRoot.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgRevisionId: data.id, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgRevisionId: data.id, + orgRootId: orgRoot.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: await this.posMasterRepository.count({ // where: { // orgRevisionId: data.id, @@ -3612,25 +3681,25 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgRevisionId: data.id, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgRevisionId: data.id, + orgRootId: orgRoot.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgRevisionId: data.id, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgRevisionId: data.id, + orgRootId: orgRoot.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: // await this.posMasterRepository.count({ // where: { @@ -3675,27 +3744,27 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgRevisionId: data.id, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - orgChild4Id: orgChild4.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgRevisionId: data.id, + orgRootId: orgRoot.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + orgChild4Id: orgChild4.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgRevisionId: data.id, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - orgChild4Id: orgChild4.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgRevisionId: data.id, + orgRootId: orgRoot.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + orgChild4Id: orgChild4.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: // await this.posMasterRepository.count({ // where: { @@ -3760,17 +3829,17 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevision.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgRootId: data.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgRootId: data.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgRootId: data.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgRootId: data.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: await this.posMasterRepository.count({ // where: { // orgRootId: data.id, @@ -3798,19 +3867,19 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevision.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgRootId: data.id, - orgChild1Id: orgChild1.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgRootId: data.id, + orgChild1Id: orgChild1.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgRootId: data.id, - orgChild1Id: orgChild1.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgRootId: data.id, + orgChild1Id: orgChild1.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: await this.posMasterRepository.count({ // where: { // orgRootId: data.id, @@ -3843,21 +3912,21 @@ export class OrganizationController extends Controller { totalPositionCurrentVacant: data.orgRevision.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgRootId: data.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgRootId: data.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgRootId: data.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgRootId: data.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: await this.posMasterRepository.count({ // where: { // orgRootId: data.id, @@ -3893,23 +3962,23 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevision.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgRootId: data.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgRootId: data.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgRootId: data.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgRootId: data.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: await this.posMasterRepository.count({ // where: { // orgRootId: data.id, @@ -3948,25 +4017,25 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevision.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgRootId: data.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - orgChild4Id: orgChild4.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgRootId: data.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + orgChild4Id: orgChild4.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgRootId: data.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - orgChild4Id: orgChild4.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgRootId: data.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + orgChild4Id: orgChild4.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: // await this.posMasterRepository.count({ // where: { @@ -4024,17 +4093,17 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevision.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgChild1Id: data.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgChild1Id: data.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgChild1Id: data.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgChild1Id: data.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: await this.posMasterRepository.count({ // where: { // orgChild1Id: data.id, @@ -4062,19 +4131,19 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevision.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgChild1Id: data.id, - orgChild2Id: orgChild2.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgChild1Id: data.id, + orgChild2Id: orgChild2.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgChild1Id: data.id, - orgChild2Id: orgChild2.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgChild1Id: data.id, + orgChild2Id: orgChild2.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: await this.posMasterRepository.count({ // where: { // orgChild1Id: data.id, @@ -4107,21 +4176,21 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevision.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgRevisionId: data.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgRevisionId: data.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgRevisionId: data.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgRevisionId: data.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: await this.posMasterRepository.count({ // where: { // orgRevisionId: data.id, @@ -4157,23 +4226,23 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevision.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgRevisionId: data.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - orgChild4Id: orgChild4.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgRevisionId: data.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + orgChild4Id: orgChild4.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgRevisionId: data.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - orgChild4Id: orgChild4.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgRevisionId: data.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + orgChild4Id: orgChild4.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: await this.posMasterRepository.count({ // where: { // orgRevisionId: data.id, @@ -4221,17 +4290,17 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevision.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgChild2Id: data.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgChild2Id: data.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgChild2Id: data.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgChild2Id: data.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: await this.posMasterRepository.count({ // where: { // orgChild2Id: data.id, @@ -4259,19 +4328,19 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevision.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgChild2Id: data.id, - orgChild3Id: orgChild3.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgChild2Id: data.id, + orgChild3Id: orgChild3.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgChild2Id: data.id, - orgChild3Id: orgChild3.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgChild2Id: data.id, + orgChild3Id: orgChild3.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: await this.posMasterRepository.count({ // where: { // orgChild2Id: data.id, @@ -4304,21 +4373,21 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevision.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgChild2Id: data.id, - orgChild3Id: orgChild3.id, - orgChild4Id: orgChild4.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgChild2Id: data.id, + orgChild3Id: orgChild3.id, + orgChild4Id: orgChild4.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgChild2Id: data.id, - orgChild3Id: orgChild3.id, - orgChild4Id: orgChild4.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgChild2Id: data.id, + orgChild3Id: orgChild3.id, + orgChild4Id: orgChild4.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: await this.posMasterRepository.count({ // where: { // orgChild2Id: data.id, @@ -4362,17 +4431,17 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevision.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgChild3Id: data.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgChild3Id: data.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgChild3Id: data.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgChild3Id: data.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: await this.posMasterRepository.count({ // where: { // orgChild3Id: data.id, @@ -4400,19 +4469,19 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevision.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgChild3Id: data.id, - orgChild4Id: orgChild4.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgChild3Id: data.id, + orgChild4Id: orgChild4.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgChild3Id: data.id, - orgChild4Id: orgChild4.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgChild3Id: data.id, + orgChild4Id: orgChild4.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: await this.posMasterRepository.count({ // where: { // orgChild3Id: data.id, @@ -4452,17 +4521,17 @@ export class OrganizationController extends Controller { totalPositionVacant: data.orgRevision.orgRevisionIsDraft == true ? await this.posMasterRepository.count({ - where: { - orgChild4Id: data.id, - next_holderId: IsNull() || "", - }, - }) + where: { + orgChild4Id: data.id, + next_holderId: IsNull() || "", + }, + }) : await this.posMasterRepository.count({ - where: { - orgChild4Id: data.id, - current_holderId: IsNull() || "", - }, - }), + where: { + orgChild4Id: data.id, + current_holderId: IsNull() || "", + }, + }), // totalPositionCurrentVacant: await this.posMasterRepository.count({ // where: { // orgChild4Id: data.id, @@ -5414,88 +5483,88 @@ export class OrganizationController extends Controller { const orgChild1Data = orgRootIds && orgRootIds.length > 0 ? await AppDataSource.getRepository(OrgChild1) - .createQueryBuilder("orgChild1") - .where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds }) - // .andWhere( - // _data.child1 != undefined && _data.child1 != null - // ? _data.child1[0] != null - // ? `orgChild1.id IN (:...node)` - // : `orgChild1.id is null` - // : "1=1", - // { - // node: _data.child1, - // }, - // ) - .leftJoinAndSelect("orgChild1.posMasters", "posMasters") - .leftJoinAndSelect("posMasters.current_holder", "current_holder") - .orderBy("orgChild1.orgChild1Order", "ASC") - .getMany() + .createQueryBuilder("orgChild1") + .where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds }) + // .andWhere( + // _data.child1 != undefined && _data.child1 != null + // ? _data.child1[0] != null + // ? `orgChild1.id IN (:...node)` + // : `orgChild1.id is null` + // : "1=1", + // { + // node: _data.child1, + // }, + // ) + .leftJoinAndSelect("orgChild1.posMasters", "posMasters") + .leftJoinAndSelect("posMasters.current_holder", "current_holder") + .orderBy("orgChild1.orgChild1Order", "ASC") + .getMany() : []; const orgChild1Ids = orgChild1Data.map((orgChild1) => orgChild1.id) || null; const orgChild2Data = orgChild1Ids && orgChild1Ids.length > 0 ? await AppDataSource.getRepository(OrgChild2) - .createQueryBuilder("orgChild2") - .where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids }) - // .andWhere( - // _data.child2 != undefined && _data.child2 != null - // ? _data.child2[0] != null - // ? `orgChild2.id IN (:...node)` - // : `orgChild2.id is null` - // : "1=1", - // { - // node: _data.child2, - // }, - // ) - .leftJoinAndSelect("orgChild2.posMasters", "posMasters") - .leftJoinAndSelect("posMasters.current_holder", "current_holder") - .orderBy("orgChild2.orgChild2Order", "ASC") - .getMany() + .createQueryBuilder("orgChild2") + .where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids }) + // .andWhere( + // _data.child2 != undefined && _data.child2 != null + // ? _data.child2[0] != null + // ? `orgChild2.id IN (:...node)` + // : `orgChild2.id is null` + // : "1=1", + // { + // node: _data.child2, + // }, + // ) + .leftJoinAndSelect("orgChild2.posMasters", "posMasters") + .leftJoinAndSelect("posMasters.current_holder", "current_holder") + .orderBy("orgChild2.orgChild2Order", "ASC") + .getMany() : []; const orgChild2Ids = orgChild2Data.map((orgChild2) => orgChild2.id) || null; const orgChild3Data = orgChild2Ids && orgChild2Ids.length > 0 ? await AppDataSource.getRepository(OrgChild3) - .createQueryBuilder("orgChild3") - .where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids }) - // .andWhere( - // _data.child3 != undefined && _data.child3 != null - // ? _data.child3[0] != null - // ? `orgChild3.id IN (:...node)` - // : `orgChild3.id is null` - // : "1=1", - // { - // node: _data.child3, - // }, - // ) - .leftJoinAndSelect("orgChild3.posMasters", "posMasters") - .leftJoinAndSelect("posMasters.current_holder", "current_holder") - .orderBy("orgChild3.orgChild3Order", "ASC") - .getMany() + .createQueryBuilder("orgChild3") + .where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids }) + // .andWhere( + // _data.child3 != undefined && _data.child3 != null + // ? _data.child3[0] != null + // ? `orgChild3.id IN (:...node)` + // : `orgChild3.id is null` + // : "1=1", + // { + // node: _data.child3, + // }, + // ) + .leftJoinAndSelect("orgChild3.posMasters", "posMasters") + .leftJoinAndSelect("posMasters.current_holder", "current_holder") + .orderBy("orgChild3.orgChild3Order", "ASC") + .getMany() : []; const orgChild3Ids = orgChild3Data.map((orgChild3) => orgChild3.id) || null; const orgChild4Data = orgChild3Ids && orgChild3Ids.length > 0 ? await AppDataSource.getRepository(OrgChild4) - .createQueryBuilder("orgChild4") - .where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids }) - // .andWhere( - // _data.child4 != undefined && _data.child4 != null - // ? _data.child4[0] != null - // ? `orgChild4.id IN (:...node)` - // : `orgChild4.id is null` - // : "1=1", - // { - // node: _data.child4, - // }, - // ) - .leftJoinAndSelect("orgChild4.posMasters", "posMasters") - .leftJoinAndSelect("posMasters.current_holder", "current_holder") - .orderBy("orgChild4.orgChild4Order", "ASC") - .getMany() + .createQueryBuilder("orgChild4") + .where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids }) + // .andWhere( + // _data.child4 != undefined && _data.child4 != null + // ? _data.child4[0] != null + // ? `orgChild4.id IN (:...node)` + // : `orgChild4.id is null` + // : "1=1", + // { + // node: _data.child4, + // }, + // ) + .leftJoinAndSelect("orgChild4.posMasters", "posMasters") + .leftJoinAndSelect("posMasters.current_holder", "current_holder") + .orderBy("orgChild4.orgChild4Order", "ASC") + .getMany() : []; // const formattedData = orgRootData.map((orgRoot) => { @@ -5945,159 +6014,159 @@ export class OrganizationController extends Controller { const orgChild1Data = orgRootIds && orgRootIds.length > 0 ? await AppDataSource.getRepository(OrgChild1) - .createQueryBuilder("orgChild1") - .where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds }) - .andWhere( - _data.child1 != undefined && _data.child1 != null - ? _data.child1[0] != null - ? `orgChild1.id IN (:...node)` - : `orgChild1.id is ${_data.privilege == "PARENT" ? "not null" : "null"}` - : "1=1", - { - node: _data.child1, - }, - ) - .select([ - "orgChild1.id", - "orgChild1.ancestorDNA", - "orgChild1.orgChild1Name", - "orgChild1.orgChild1ShortName", - "orgChild1.orgChild1Code", - "orgChild1.orgChild1Order", - "orgChild1.orgChild1PhoneEx", - "orgChild1.orgChild1PhoneIn", - "orgChild1.orgChild1Fax", - "orgChild1.orgRootId", - "orgChild1.orgChild1Rank", - "orgChild1.orgChild1RankSub", - "orgChild1.DEPARTMENT_CODE", - "orgChild1.DIVISION_CODE", - "orgChild1.SECTION_CODE", - "orgChild1.JOB_CODE", - "orgChild1.responsibility", - ]) - .orderBy("orgChild1.orgChild1Order", "ASC") - .getMany() + .createQueryBuilder("orgChild1") + .where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds }) + .andWhere( + _data.child1 != undefined && _data.child1 != null + ? _data.child1[0] != null + ? `orgChild1.id IN (:...node)` + : `orgChild1.id is ${_data.privilege == "PARENT" ? "not null" : "null"}` + : "1=1", + { + node: _data.child1, + }, + ) + .select([ + "orgChild1.id", + "orgChild1.ancestorDNA", + "orgChild1.orgChild1Name", + "orgChild1.orgChild1ShortName", + "orgChild1.orgChild1Code", + "orgChild1.orgChild1Order", + "orgChild1.orgChild1PhoneEx", + "orgChild1.orgChild1PhoneIn", + "orgChild1.orgChild1Fax", + "orgChild1.orgRootId", + "orgChild1.orgChild1Rank", + "orgChild1.orgChild1RankSub", + "orgChild1.DEPARTMENT_CODE", + "orgChild1.DIVISION_CODE", + "orgChild1.SECTION_CODE", + "orgChild1.JOB_CODE", + "orgChild1.responsibility", + ]) + .orderBy("orgChild1.orgChild1Order", "ASC") + .getMany() : []; const orgChild1Ids = orgChild1Data.map((orgChild1) => orgChild1.id) || null; const orgChild2Data = orgChild1Ids && orgChild1Ids.length > 0 ? await AppDataSource.getRepository(OrgChild2) - .createQueryBuilder("orgChild2") - .where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids }) - .andWhere( - _data.child2 != undefined && _data.child2 != null - ? _data.child2[0] != null - ? `orgChild2.id IN (:...node)` - : `orgChild2.id is null` - : "1=1", - { - node: _data.child2, - }, - ) - .select([ - "orgChild2.id", - "orgChild2.ancestorDNA", - "orgChild2.orgChild2Name", - "orgChild2.orgChild2ShortName", - "orgChild2.orgChild2Code", - "orgChild2.orgChild2Order", - "orgChild2.orgChild2PhoneEx", - "orgChild2.orgChild2PhoneIn", - "orgChild2.orgChild2Fax", - "orgChild2.orgRootId", - "orgChild2.orgChild2Rank", - "orgChild2.orgChild2RankSub", - "orgChild2.DEPARTMENT_CODE", - "orgChild2.DIVISION_CODE", - "orgChild2.SECTION_CODE", - "orgChild2.JOB_CODE", - "orgChild2.orgChild1Id", - "orgChild2.responsibility", - ]) - .orderBy("orgChild2.orgChild2Order", "ASC") - .getMany() + .createQueryBuilder("orgChild2") + .where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids }) + .andWhere( + _data.child2 != undefined && _data.child2 != null + ? _data.child2[0] != null + ? `orgChild2.id IN (:...node)` + : `orgChild2.id is null` + : "1=1", + { + node: _data.child2, + }, + ) + .select([ + "orgChild2.id", + "orgChild2.ancestorDNA", + "orgChild2.orgChild2Name", + "orgChild2.orgChild2ShortName", + "orgChild2.orgChild2Code", + "orgChild2.orgChild2Order", + "orgChild2.orgChild2PhoneEx", + "orgChild2.orgChild2PhoneIn", + "orgChild2.orgChild2Fax", + "orgChild2.orgRootId", + "orgChild2.orgChild2Rank", + "orgChild2.orgChild2RankSub", + "orgChild2.DEPARTMENT_CODE", + "orgChild2.DIVISION_CODE", + "orgChild2.SECTION_CODE", + "orgChild2.JOB_CODE", + "orgChild2.orgChild1Id", + "orgChild2.responsibility", + ]) + .orderBy("orgChild2.orgChild2Order", "ASC") + .getMany() : []; const orgChild2Ids = orgChild2Data.map((orgChild2) => orgChild2.id) || null; const orgChild3Data = orgChild2Ids && orgChild2Ids.length > 0 ? await AppDataSource.getRepository(OrgChild3) - .createQueryBuilder("orgChild3") - .where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids }) - .andWhere( - _data.child3 != undefined && _data.child3 != null - ? _data.child3[0] != null - ? `orgChild3.id IN (:...node)` - : `orgChild3.id is null` - : "1=1", - { - node: _data.child3, - }, - ) - .select([ - "orgChild3.id", - "orgChild3.ancestorDNA", - "orgChild3.orgChild3Name", - "orgChild3.orgChild3ShortName", - "orgChild3.orgChild3Code", - "orgChild3.orgChild3Order", - "orgChild3.orgChild3PhoneEx", - "orgChild3.orgChild3PhoneIn", - "orgChild3.orgChild3Fax", - "orgChild3.orgRootId", - "orgChild3.orgChild3Rank", - "orgChild3.orgChild3RankSub", - "orgChild3.DEPARTMENT_CODE", - "orgChild3.DIVISION_CODE", - "orgChild3.SECTION_CODE", - "orgChild3.JOB_CODE", - "orgChild3.orgChild2Id", - "orgChild3.responsibility", - ]) - .orderBy("orgChild3.orgChild3Order", "ASC") - .getMany() + .createQueryBuilder("orgChild3") + .where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids }) + .andWhere( + _data.child3 != undefined && _data.child3 != null + ? _data.child3[0] != null + ? `orgChild3.id IN (:...node)` + : `orgChild3.id is null` + : "1=1", + { + node: _data.child3, + }, + ) + .select([ + "orgChild3.id", + "orgChild3.ancestorDNA", + "orgChild3.orgChild3Name", + "orgChild3.orgChild3ShortName", + "orgChild3.orgChild3Code", + "orgChild3.orgChild3Order", + "orgChild3.orgChild3PhoneEx", + "orgChild3.orgChild3PhoneIn", + "orgChild3.orgChild3Fax", + "orgChild3.orgRootId", + "orgChild3.orgChild3Rank", + "orgChild3.orgChild3RankSub", + "orgChild3.DEPARTMENT_CODE", + "orgChild3.DIVISION_CODE", + "orgChild3.SECTION_CODE", + "orgChild3.JOB_CODE", + "orgChild3.orgChild2Id", + "orgChild3.responsibility", + ]) + .orderBy("orgChild3.orgChild3Order", "ASC") + .getMany() : []; const orgChild3Ids = orgChild3Data.map((orgChild3) => orgChild3.id) || null; const orgChild4Data = orgChild3Ids && orgChild3Ids.length > 0 ? await AppDataSource.getRepository(OrgChild4) - .createQueryBuilder("orgChild4") - .where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids }) - .andWhere( - _data.child4 != undefined && _data.child4 != null - ? _data.child4[0] != null - ? `orgChild4.id IN (:...node)` - : `orgChild4.id is null` - : "1=1", - { - node: _data.child4, - }, - ) - .select([ - "orgChild4.id", - "orgChild4.ancestorDNA", - "orgChild4.orgChild4Name", - "orgChild4.orgChild4ShortName", - "orgChild4.orgChild4Code", - "orgChild4.orgChild4Order", - "orgChild4.orgChild4PhoneEx", - "orgChild4.orgChild4PhoneIn", - "orgChild4.orgChild4Fax", - "orgChild4.orgRootId", - "orgChild4.orgChild4Rank", - "orgChild4.orgChild4RankSub", - "orgChild4.DEPARTMENT_CODE", - "orgChild4.DIVISION_CODE", - "orgChild4.SECTION_CODE", - "orgChild4.JOB_CODE", - "orgChild4.orgChild3Id", - "orgChild4.responsibility", - ]) - .orderBy("orgChild4.orgChild4Order", "ASC") - .getMany() + .createQueryBuilder("orgChild4") + .where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids }) + .andWhere( + _data.child4 != undefined && _data.child4 != null + ? _data.child4[0] != null + ? `orgChild4.id IN (:...node)` + : `orgChild4.id is null` + : "1=1", + { + node: _data.child4, + }, + ) + .select([ + "orgChild4.id", + "orgChild4.ancestorDNA", + "orgChild4.orgChild4Name", + "orgChild4.orgChild4ShortName", + "orgChild4.orgChild4Code", + "orgChild4.orgChild4Order", + "orgChild4.orgChild4PhoneEx", + "orgChild4.orgChild4PhoneIn", + "orgChild4.orgChild4Fax", + "orgChild4.orgRootId", + "orgChild4.orgChild4Rank", + "orgChild4.orgChild4RankSub", + "orgChild4.DEPARTMENT_CODE", + "orgChild4.DIVISION_CODE", + "orgChild4.SECTION_CODE", + "orgChild4.JOB_CODE", + "orgChild4.orgChild3Id", + "orgChild4.responsibility", + ]) + .orderBy("orgChild4.orgChild4Order", "ASC") + .getMany() : []; // const formattedData = orgRootData.map((orgRoot) => {