From 4b05629c29ad327c049d375c77e29dae30b34663 Mon Sep 17 00:00:00 2001 From: kittapath Date: Mon, 6 Jan 2025 17:34:47 +0700 Subject: [PATCH] search position --- src/controllers/PositionController.ts | 58 +++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 960fd984..d60a3b96 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -337,6 +337,64 @@ export class PositionController extends Controller { return new HttpSuccess(posDict.id); } + /** + * API ค้นหารายการตำแหน่ง + * + * @summary ORG_029 - ค้นหารายการตำแหน่ง (ADMIN) #32 + * + */ + @Post("position/search") + async findPositionSearch( + @Body() + requestBody: { + posLevel: string; + posType: string; + }, + ) { + let findPosDict = await this.posDictRepository.find({ + relations: ["posType", "posLevel"], + where: { + posTypeId: requestBody.posType, + posLevelId: requestBody.posLevel, + }, + order: { + posDictName: "ASC", + createdAt: "DESC", + posType: { + posTypeRank: "ASC", + createdAt: "DESC", + }, + posLevel: { + posLevelRank: "ASC", + createdAt: "DESC", + }, + }, + }); + + const mapDataPosDict = await Promise.all( + findPosDict.map(async (item: any) => { + return { + id: item.id, + positionName: item.posDictName, + positionField: item.posDictField, + posTypeId: item.posTypeId, + posTypeName: item.posType == null ? null : item.posType.posTypeName, + posLevelId: item.posLevelId, + posLevelName: item.posLevel == null ? null : item.posLevel.posLevelName, + positionExecutiveField: item.posDictExecutiveField, + positionArea: item.posDictArea, + isSpecial: item.isSpecial, + positionIsSelected: false, + createdAt: item.createdAt, + lastUpdatedAt: item.lastUpdatedAt, + lastUpdateFullName: item.lastUpdateFullName, + }; + }), + ); + + return new HttpSuccess(mapDataPosDict); + } + /** * API แก้ไขตำแหน่ง *