diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index c0f48714..b34b8390 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -24,7 +24,7 @@ import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import { CreatePosDict, CreatePosDictExe, PosDict, UpdatePosDict } from "../entities/PosDict"; import HttpError from "../interfaces/http-error"; -import { Equal, ILike, In, IsNull, Like, Not, Brackets } from "typeorm"; +import { Equal, ILike, In, IsNull, Like, Not, Brackets,MoreThan } from "typeorm"; import { CreatePosMaster, PosMaster } from "../entities/PosMaster"; import { OrgRevision } from "../entities/OrgRevision"; import { OrgRoot } from "../entities/OrgRoot"; @@ -2642,4 +2642,86 @@ export class PositionController extends Controller { ); return new HttpSuccess({ data: formattedData, total }); } + /** + * API ค้นหาตำแหน่งในระบบสมัครสอบ + * + * @summary ค้นหาตำแหน่งในระบบสมัครสอบ + * + */ + @Post("placement/searchh") + async searchPlacementt( + @Body() + body: { + node: number; + nodeId: string; + position: string; + typeCommand: string; + posType: string; + posLevel: string; + }, + ) { + let typeCondition: any = {}; + let conditionA: any = {}; + let posTypeRank: any = {}; + + posTypeRank = await this.posTypeRepository.findOne({ + where: { id: String(posTypeRank?.posTypeId) }, + }); + if (body.typeCommand == "APPOINTED" || body.typeCommand == "MOVE") { + conditionA = { + posTypeId: body.posType, + posLevelId: body.posLevel, + }; + } else if (body.typeCommand == "APPOINT") { + conditionA = { + posTypeId: body.posType, + + posLevel: { + posTypeRank: MoreThan(posTypeRank), + }, + }; + } + + if (body.node === 0) { + typeCondition = { + orgRootId: body.nodeId, + orgChild1Id: IsNull(), + next_holderId: IsNull(), + positions: conditionA, + }; + } else if (body.node === 1) { + typeCondition = { + orgChild1Id: body.nodeId, + orgChild2Id: IsNull(), + next_holderId: IsNull(), + positions: conditionA, + }; + } else if (body.node === 2) { + typeCondition = { + orgChild2Id: body.nodeId, + orgChild3Id: IsNull(), + next_holderId: IsNull(), + positions: conditionA, + }; + } else if (body.node === 3) { + typeCondition = { + orgChild3Id: body.nodeId, + orgChild4Id: IsNull(), + next_holderId: IsNull(), + positions: { + posTypeId: body.posType, + posLevelId: body.posLevel, + }, + }; + } else if (body.node === 4) { + typeCondition = { + orgChild4Id: body.nodeId, + next_holderId: IsNull(), + positions: { + posTypeId: body.posType, + posLevelId: body.posLevel, + }, + }; + } } +