From a9dd7d089a78e69c6f738ca946cc5afc75361269 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 26 Nov 2024 14:35:14 +0700 Subject: [PATCH] =?UTF-8?q?serch=20name=20=E0=B8=AA=E0=B8=B4=E0=B8=97?= =?UTF-8?q?=E0=B8=98=E0=B8=B4=E0=B9=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/PositionController.ts | 36 +++++++++++++++++---------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 6ff78f92..5f742081 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -1411,6 +1411,8 @@ export class PositionController extends Controller { } let findPosition: any; let masterId = new Array(); + let _authRoleId = new Array(); + let _exitsRole = false; if (body.keyword != null && body.keyword != "") { const findTypes: PosType[] = await this.posTypeRepository.find({ where: { posTypeName: Like(`%${body.keyword}%`) }, @@ -1449,6 +1451,17 @@ export class PositionController extends Controller { keywordAsInt = "P@ssw0rd!z"; } masterId = [...new Set(masterId)]; + + //serch name สิทธิ์ + _authRoleId = await this.authRoleRepo.find({ + where: { + roleName: Like(`%${body.keyword}%`), + } + }); + if (_authRoleId.length > 0) { + _exitsRole = true; + _authRoleId = [...new Set(_authRoleId.map((x) => x.id))]; + } } const revisionCondition = { @@ -1477,11 +1490,20 @@ export class PositionController extends Controller { .leftJoinAndSelect("posMaster.next_holder", "next_holder") .leftJoinAndSelect("posMaster.orgRevision", "orgRevision") .leftJoinAndSelect("posMaster.posMasterAssigns", "posMasterAssigns") - // .leftJoinAndSelect("posMaster.authRole", "authRole") .leftJoinAndSelect("posMasterAssigns.assign", "assign") .leftJoinAndSelect("current_holder.posType", "posType") .leftJoinAndSelect("current_holder.posLevel", "posLevel") .where(conditions) + .orWhere( + new Brackets((qb) => { + if (body.keyword != null && body.keyword != "" && _exitsRole) { + qb.andWhere("posMaster.authRoleId IN (:...authRoleId)", { authRoleId: _authRoleId }) + .andWhere(checkChildConditions) + .andWhere(typeCondition) + .andWhere(revisionCondition); + } + }) + ) .orWhere( new Brackets((qb) => { qb.andWhere( @@ -1591,18 +1613,6 @@ export class PositionController extends Controller { .take(body.pageSize) .getManyAndCount(); - //serch name สิทธิ์ - // if(posMaster.length == 0 && body.keyword != null && body.keyword != "") { - // let _authRole:any; - // let _masterIdRole:any - // _authRole = await this.authRoleRepo.find({ - // where: { - // roleName: Like(`%${body.keyword}%`), - // }, - // relations: ["posMasters"] - // }); - // _masterIdRole = [...new Set(_authRole.map((x: any) => x.posMasters.map((y: any) => y.id)).flat())]; - // } //แก้ค้นหา let _position: any[] = []; let x: any = null;