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(