diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 420ffd3d..2f23cb7b 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, PosDict } from "../entities/PosDict"; import HttpError from "../interfaces/http-error"; -import { In, Like } from "typeorm"; +import { In, IsNull, Like } from "typeorm"; import { CreatePosMaster, PosMaster } from "../entities/PosMaster"; import { OrgRevision } from "../entities/OrgRevision"; import { OrgRoot } from "../entities/OrgRoot"; @@ -731,23 +731,44 @@ export class PositionController extends Controller { ) { try { let typeCondition: any = {}; + let checkChildConditions: any = {}; if (body.type === 0) { typeCondition = { orgRootId: body.id, }; + if (!body.isAll) { + checkChildConditions = { + orgChild1Id: IsNull(), + }; + } } else if (body.type === 1) { typeCondition = { orgChild1Id: body.id, }; + if (!body.isAll) { + checkChildConditions = { + orgChild2Id: IsNull(), + }; + } } else if (body.type === 2) { typeCondition = { orgChild2Id: body.id, }; + if (!body.isAll) { + checkChildConditions = { + orgChild3Id: IsNull(), + }; + } } else if (body.type === 3) { typeCondition = { orgChild3Id: body.id, }; + if (!body.isAll) { + checkChildConditions = { + orgChild4Id: IsNull(), + }; + } } else if (body.type === 4) { typeCondition = { orgChild4Id: body.id, @@ -755,7 +776,10 @@ export class PositionController extends Controller { } const posMaster = await this.posMasterRepository.find({ - where: typeCondition, + where: { + ...typeCondition, + ...checkChildConditions, + }, }); if (!posMaster || posMaster.length === 0) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");