add search all

This commit is contained in:
AdisakKanthawilang 2024-09-03 17:44:47 +07:00
parent 92b1803db0
commit c6ed6e72b9

View file

@ -387,9 +387,6 @@ export class PositionController extends Controller {
relations: ["posType", "posLevel", "posExecutive"],
order: { posDictName: "ASC" },
});
// if (!findPosDict) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
// }
break;
case "positionField":
@ -398,9 +395,6 @@ export class PositionController extends Controller {
relations: ["posType", "posLevel", "posExecutive"],
order: { posDictField: "ASC" },
});
// if (!findPosDict) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
// }
break;
case "positionType":
@ -448,9 +442,6 @@ export class PositionController extends Controller {
relations: ["posType", "posLevel", "posExecutive"],
order: { posDictName: "ASC" },
});
// if (!findPosDict) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
// }
break;
case "positionArea":
@ -459,19 +450,30 @@ export class PositionController extends Controller {
relations: ["posType", "posLevel", "posExecutive"],
order: { posDictName: "ASC" },
});
// if (!findPosDict) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
// }
break;
case "all":
findPosDict = await this.posDictRepository.find({
where: [
{ posDictName: Like(`%${keyword}%`) },
{ posDictField: Like(`%${keyword}%`) },
{ posTypeId: In(await this.posTypeRepository.find({ where: { posTypeName: Like(`%${keyword}%`) }, select: ["id"] }).then(types => types.map(type => type.id))) },
{ posLevelId: In(await this.posLevelRepository.find({ where: { posLevelName: Like(`%${keyword}%`) }, select: ["id"] }).then(levels => levels.map(level => level.id))) },
{ posExecutiveId: In(await this.posExecutiveRepository.find({ where: { posExecutiveName: Like(`%${keyword}%`) }, select: ["id"] }).then(executives => executives.map(exec => exec.id))) },
{ posDictExecutiveField: Like(`%${keyword}%`) },
{ posDictArea: Like(`%${keyword}%`) }
],
relations: ["posType", "posLevel", "posExecutive"],
order: { posDictName: "ASC" },
});
break;
default:
findPosDict = await this.posDictRepository.find({
relations: ["posType", "posLevel", "posExecutive"],
order: { posDictName: "ASC" },
});
// if (!findPosDict) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
// }
break;
}