From 07e1d04defacf94cb0087e33766e73d8af1f9335 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 9 May 2024 18:01:47 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=84=E0=B9=89?= =?UTF-8?q?=E0=B8=99=E0=B8=AB=E0=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/PositionController.ts | 33 +++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index e869d716..da545b3e 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -1136,7 +1136,7 @@ export class PositionController extends Controller { }, ]; - const [posMaster, total] = await AppDataSource.getRepository(PosMaster) + let [posMaster, total] = await AppDataSource.getRepository(PosMaster) .createQueryBuilder("posMaster") .leftJoinAndSelect("posMaster.orgRoot", "orgRoot") .leftJoinAndSelect("posMaster.orgChild1", "orgChild1") @@ -1196,6 +1196,35 @@ export class PositionController extends Controller { .take(body.pageSize) .getManyAndCount(); + //แก้ค้นหา + let _position: any[] = []; + let x: any = null + let y: any = null + if (body.keyword != null && body.keyword != ""){ + const position = await this.positionRepository.find({ + relations: ["posType", "posLevel", "posExecutive"], + where: { posMasterId: In(posMaster.map(x => x.id))}, + order: { createdAt: "ASC" } + }); + for(let data of position){ + x = data.posMasterId + if(y != x){ + if( + data.positionName.includes(body.keyword) || + data.posType.posTypeName.includes(body.keyword) || + data.posLevel.posLevelName.includes(body.keyword) + ){ + _position.push(data) + } + } + y = x + } + } + + if(_position.length > 0){ + posMaster = posMaster.filter((x) => _position.some(y => y.posMasterId === x.id)); + } + const formattedData = await Promise.all( posMaster.map(async (posMaster) => { const positions = await this.positionRepository.find({ @@ -1296,7 +1325,7 @@ export class PositionController extends Controller { profilePosition: profile == null || profile.position == null ? null : profile.position, profilePostype: type == null || type.posTypeName == null ? null : type.posTypeName, profilePoslevel: level == null || level.posLevelName == null ? null : level.posLevelName, - positions: positions.map((position) => ({ + positions: positions.map((position:any) => ({ id: position.id, positionName: position.positionName, positionField: position.positionField,