แก้ค้นหา

This commit is contained in:
Bright 2024-05-09 18:01:47 +07:00
parent 2217355dea
commit 07e1d04def

View file

@ -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,