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,