From e3275e0b79fd8a4fcc5dd9ed41dd8adfc29c735d Mon Sep 17 00:00:00 2001 From: kittapath Date: Wed, 8 Jan 2025 16:25:54 +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=81=E0=B8=A3=E0=B8=A3=E0=B8=A1=E0=B8=81?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 93 +++++++++++++++++++++++----- 1 file changed, 78 insertions(+), 15 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index f74bbbef..792a924b 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -1308,16 +1308,37 @@ export class ProfileController extends Controller { let condition: any = { orgRootId: posMaster.orgRootId || "", + id: Not(posMaster.current_holderId || ""), }; + let conditionNow: any = { + orgRootId: posMaster.orgRootId || "", + orgChild1Id: posMaster.orgChild1Id || "", + orgChild2Id: posMaster.orgChild2Id || "", + orgChild3Id: posMaster.orgChild3Id || "", + orgChild4Id: posMaster.orgChild4Id || "", + id: Not(posMaster.current_holderId || ""), + }; + if (posMaster.orgChild2Id == null) { + condition.orgChild1Id = ""; + } else if (posMaster.orgChild3Id == null) { + condition.orgChild2Id = ""; + } else if (posMaster.orgChild4Id == null) { + condition.orgChild3Id = ""; + } else { + condition.orgChild4Id = ""; + } if (body.isDirector == true) { - condition = { - orgRootId: posMaster.orgRootId || "", - isDirector: true, - }; + condition.isDirector = true; + conditionNow.isDirector = true; } const [lists, total] = await AppDataSource.getRepository(viewDirectorActing) .createQueryBuilder("viewDirectorActing") - .andWhere(condition) + // .andWhere(condition) + .andWhere( + new Brackets((qb) => { + qb.orWhere(condition).orWhere(conditionNow); + }), + ) .andWhere( new Brackets((qb) => { qb.orWhere( @@ -1402,16 +1423,37 @@ export class ProfileController extends Controller { let condition: any = { orgRootId: posMaster.orgRootId || "", + id: Not(posMaster.current_holderId || ""), }; - // if (body.isDirector == true) { - condition = { + let conditionNow: any = { orgRootId: posMaster.orgRootId || "", - isDirector: true, + orgChild1Id: posMaster.orgChild1Id || "", + orgChild2Id: posMaster.orgChild2Id || "", + orgChild3Id: posMaster.orgChild3Id || "", + orgChild4Id: posMaster.orgChild4Id || "", + id: Not(posMaster.current_holderId || ""), }; - // } + if (posMaster.orgChild2Id == null) { + condition.orgChild1Id = ""; + } else if (posMaster.orgChild3Id == null) { + condition.orgChild2Id = ""; + } else if (posMaster.orgChild4Id == null) { + condition.orgChild3Id = ""; + } else { + condition.orgChild4Id = ""; + } + if (body.isDirector == true) { + condition.isDirector = true; + conditionNow.isDirector = true; + } const [lists, total] = await AppDataSource.getRepository(viewDirectorActing) .createQueryBuilder("viewDirectorActing") - .andWhere(condition) + // .andWhere(condition) + .andWhere( + new Brackets((qb) => { + qb.orWhere(condition).orWhere(conditionNow); + }), + ) .andWhere( new Brackets((qb) => { qb.orWhere( @@ -1471,16 +1513,37 @@ export class ProfileController extends Controller { let condition: any = { orgRootId: posMaster.orgRootId || "", + id: Not(posMaster.current_holderId || ""), }; + let conditionNow: any = { + orgRootId: posMaster.orgRootId || "", + orgChild1Id: posMaster.orgChild1Id || "", + orgChild2Id: posMaster.orgChild2Id || "", + orgChild3Id: posMaster.orgChild3Id || "", + orgChild4Id: posMaster.orgChild4Id || "", + id: Not(posMaster.current_holderId || ""), + }; + if (posMaster.orgChild2Id == null) { + condition.orgChild1Id = ""; + } else if (posMaster.orgChild3Id == null) { + condition.orgChild2Id = ""; + } else if (posMaster.orgChild4Id == null) { + condition.orgChild3Id = ""; + } else { + condition.orgChild4Id = ""; + } if (body.isDirector == true) { - condition = { - orgRootId: posMaster.orgRootId || "", - isDirector: true, - }; + condition.isDirector = true; + conditionNow.isDirector = true; } const [lists, total] = await AppDataSource.getRepository(viewDirector) .createQueryBuilder("viewDirector") - .andWhere(condition) + // .andWhere(condition) + .andWhere( + new Brackets((qb) => { + qb.orWhere(condition).orWhere(conditionNow); + }), + ) .andWhere( new Brackets((qb) => { qb.orWhere(