From a5447eda95d08585172db9ff19674a011a2c7d3e Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 4 Sep 2024 14:18:15 +0700 Subject: [PATCH] fix search and checkpoint --- src/controllers/OrganizationController.ts | 66 ++++++++++++++++++++++- src/controllers/PositionController.ts | 2 +- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index d3f43d1d..a154328a 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -606,7 +606,7 @@ export class OrganizationController extends Controller { if (!orgRevision) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } - + const orgRootData = await AppDataSource.getRepository(OrgRoot) .createQueryBuilder("orgRoot") .where("orgRoot.orgRevisionId = :id", { id }) @@ -3559,7 +3559,19 @@ export class OrganizationController extends Controller { * */ @Get("act/{id}") - async detailAct(@Path() id: string) { + async detailAct(@Path() id: string, @Request() request: RequestWithUser) { + let _data = { + root: null, + child1: null, + child2: null, + child3: null, + child4: null, + }; + + if (!request.user.role.includes("SUPER_ADMIN")) { + _data = await new permission().PermissionOrgList(request, "SYS_ACTING"); + } + const orgRevision = await this.orgRevisionRepository.findOne({ where: { id } }); if (!orgRevision) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); @@ -3568,6 +3580,16 @@ export class OrganizationController extends Controller { const orgRootData = await AppDataSource.getRepository(OrgRoot) .createQueryBuilder("orgRoot") .where("orgRoot.orgRevisionId = :id", { id }) + .andWhere( + _data.root != undefined && _data.root != null + ? _data.root[0] != null + ? `orgRoot.id IN (:...node)` + : `orgRoot.id is null` + : "1=1", + { + node: _data.root, + }, + ) .leftJoinAndSelect("orgRoot.posMasters", "posMasters") .leftJoinAndSelect("posMasters.current_holder", "current_holder") .orderBy("orgRoot.orgRootOrder", "ASC") @@ -3579,6 +3601,16 @@ export class OrganizationController extends Controller { ? 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") @@ -3591,6 +3623,16 @@ export class OrganizationController extends Controller { ? 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") @@ -3603,6 +3645,16 @@ export class OrganizationController extends Controller { ? 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") @@ -3615,6 +3667,16 @@ export class OrganizationController extends Controller { ? 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") diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 7c4a5b3e..35b1263f 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -452,7 +452,7 @@ export class PositionController extends Controller { }); break; - case "all": + case "ALL": findPosDict = await this.posDictRepository.find({ where: [ { posDictName: Like(`%${keyword}%`) },