From c6ed6e72b9590918338ad0cefc99a6f70125d98f Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 3 Sep 2024 17:44:47 +0700 Subject: [PATCH] add search all --- src/controllers/PositionController.ts | 32 ++++++++++++++------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 09dcca57..7c4a5b3e 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -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; }