From 63aaadae6ad6d74f889cb78e69c63b7c03ee2dbe Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 24 Jun 2025 12:30:17 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=8A=E0=B8=B7?= =?UTF-8?q?=E0=B9=88=E0=B8=AD=E0=B8=97=E0=B8=B5=E0=B9=88=E0=B8=84=E0=B9=89?= =?UTF-8?q?=E0=B8=99=E0=B8=AB=E0=B8=B2=E0=B8=95=E0=B9=89=E0=B8=AD=E0=B8=87?= =?UTF-8?q?=E0=B8=84=E0=B9=89=E0=B8=99=E0=B8=AB=E0=B8=B2=E0=B9=84=E0=B8=94?= =?UTF-8?q?=E0=B9=89=E0=B8=95=E0=B8=B2=E0=B8=A1=E0=B8=AA=E0=B8=B4=E0=B8=97?= =?UTF-8?q?=E0=B8=98=E0=B8=B4=E0=B9=8C=20#1576?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrganizationDotnetController.ts | 106 ++++++++++++++++-- 1 file changed, 97 insertions(+), 9 deletions(-) diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index 8f1dc9c0..a1ac4736 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -60,16 +60,103 @@ export class OrganizationDotnetController extends Controller { citizenId?: string | null; firstName?: string | null; lastName?: string | null; + role?: string | null; + nodeId?: string | null; + node?: number | null; }, ) { - const profileRepository = AppDataSource.getRepository(Profile); - const queryBuilder = profileRepository + // const profileRepository = AppDataSource.getRepository(Profile); + // const queryBuilder = profileRepository + // .createQueryBuilder("profile") + // .leftJoinAndSelect("profile.posLevel", "posLevel") + // .leftJoinAndSelect("profile.posType", "posType") + // if (body.citizenId || body.firstName || body.lastName) { + // queryBuilder.where( + // new Brackets((qb) => { + // if (body.citizenId) { + // qb.orWhere("profile.citizenId LIKE :citizenId", { citizenId: `%${body.citizenId}%` }); + // } + // if (body.firstName) { + // qb.orWhere("profile.firstName LIKE :firstName", { firstName: `%${body.firstName}%` }); + // } + // if (body.lastName) { + // qb.orWhere("profile.lastName LIKE :lastName", { lastName: `%${body.lastName}%` }); + // } + // }), + // ); + // } + // const profiles = await queryBuilder.getMany(); + let condition = "1=1"; + let conditionParams = {}; + if (body.role === "CHILD") { + switch (body.node) { + case 0: + condition = "orgRoot.ancestorDNA = :nodeId"; + break; + case 1: + condition = "orgChild1.ancestorDNA = :nodeId"; + break; + case 2: + condition = "orgChild2.ancestorDNA = :nodeId"; + break; + case 3: + condition = "orgChild3.ancestorDNA = :nodeId"; + break; + case 4: + condition = "orgChild4.ancestorDNA = :nodeId"; + break; + default: + condition = "1=1"; + break; + } + conditionParams = { nodeId: body.nodeId }; + } + else if (body.role === "ROOT") { + condition = "orgRoot.ancestorDNA = :nodeId"; + conditionParams = { nodeId: body.nodeId }; + } + else if (body.role === "NORMAL") { + switch (body.node) { + case 0: + condition = "orgRoot.ancestorDNA = :nodeId AND current_holders.orgChild1 IS NULL"; + break; + case 1: + condition = "orgChild1.ancestorDNA = :nodeId AND current_holders.orgChild2 IS NULL"; + break; + case 2: + condition = "orgChild2.ancestorDNA = :nodeId AND current_holders.orgChild3 IS NULL"; + break; + case 3: + condition = "orgChild3.ancestorDNA = :nodeId AND current_holders.orgChild4 IS NULL"; + break; + case 4: + condition = "orgChild4.ancestorDNA = :nodeId"; + break; + default: + condition = "1=1"; + break; + } + conditionParams = { nodeId: body.nodeId }; + } + + const findRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false } + }); + if (!findRevision) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); + } + const profiles = await this.profileRepo .createQueryBuilder("profile") .leftJoinAndSelect("profile.posLevel", "posLevel") - .leftJoinAndSelect("profile.posType", "posType"); - - if (body.citizenId || body.firstName || body.lastName) { - queryBuilder.where( + .leftJoinAndSelect("profile.posType", "posType") + .leftJoinAndSelect("profile.current_holders", "current_holders") + .leftJoinAndSelect("current_holders.orgRoot", "orgRoot") + .leftJoinAndSelect("current_holders.orgChild1", "orgChild1") + .leftJoinAndSelect("current_holders.orgChild2", "orgChild2") + .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") + .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") + .where("current_holders.orgRevisionId = :orgRevisionId", { orgRevisionId: findRevision.id }) + .andWhere( new Brackets((qb) => { if (body.citizenId) { qb.orWhere("profile.citizenId LIKE :citizenId", { citizenId: `%${body.citizenId}%` }); @@ -81,9 +168,10 @@ export class OrganizationDotnetController extends Controller { qb.orWhere("profile.lastName LIKE :lastName", { lastName: `%${body.lastName}%` }); } }), - ); - } - const profiles = await queryBuilder.getMany(); + ) + .andWhere(condition, conditionParams) + .getMany() + return new HttpSuccess(profiles); }