diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 589a4884..dc97d087 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -3311,6 +3311,13 @@ export class PositionController extends Controller { .orderBy("posMaster.posMasterOrder", "ASC") .getManyAndCount(); + const _posType = await this.posTypeRepository.find({ + where: { posTypeName: In(["ทั่วไป", "วิชาการ"]) } + }); + const _posLevel = await this.posLevelRepository.find({ + where: { posLevelName: In(["ปฏิบัติงาน", "ปฏิบัติการ"]) } + }); + const formattedData = await Promise.all( posMaster.map(async (posMaster) => { let shortName = ""; @@ -3375,6 +3382,49 @@ export class PositionController extends Controller { nodeId = posMaster.orgRootId; } + let _position: any + if( posLevel == null && posType == null && body.position != null) { + _position = posMaster.positions + .filter((x:any) => + _posType.some((y:any) => y.id == x.posTypeId) && + _posLevel.some((z:any) => z.id == x.posLevelId) + ) + .map((position) => ({ + id: position.id, + positionName: position.positionName, + positionField: position.positionField, + posTypeId: position.posTypeId, + posTypeName: position.posType == null ? null : position.posType.posTypeName, + posLevelId: position.posLevelId, + posLevelName: position.posLevel == null ? null : position.posLevel.posLevelName, + posExecutiveId: position.posExecutiveId, + posExecutiveName: + position.posExecutive == null ? null : position.posExecutive.posExecutiveName, + positionExecutiveField: position.positionExecutiveField, + positionArea: position.positionArea, + positionIsSelected: position.positionIsSelected, + isSpecial: position.isSpecial, + })); + } + else { + _position = posMaster.positions.map((position) => ({ + id: position.id, + positionName: position.positionName, + positionField: position.positionField, + posTypeId: position.posTypeId, + posTypeName: position.posType == null ? null : position.posType.posTypeName, + posLevelId: position.posLevelId, + posLevelName: position.posLevel == null ? null : position.posLevel.posLevelName, + posExecutiveId: position.posExecutiveId, + posExecutiveName: + position.posExecutive == null ? null : position.posExecutive.posExecutiveName, + positionExecutiveField: position.positionExecutiveField, + positionArea: position.positionArea, + positionIsSelected: position.positionIsSelected, + isSpecial: position.isSpecial, + })); + } + return { id: posMaster.id, node: node, @@ -3398,22 +3448,7 @@ export class PositionController extends Controller { ? null : `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`, isPosition: posMaster.positions.filter((x) => x.positionName == body.position).length > 0, - positions: posMaster.positions.map((position) => ({ - id: position.id, - positionName: position.positionName, - positionField: position.positionField, - posTypeId: position.posTypeId, - posTypeName: position.posType == null ? null : position.posType.posTypeName, - posLevelId: position.posLevelId, - posLevelName: position.posLevel == null ? null : position.posLevel.posLevelName, - posExecutiveId: position.posExecutiveId, - posExecutiveName: - position.posExecutive == null ? null : position.posExecutive.posExecutiveName, - positionExecutiveField: position.positionExecutiveField, - positionArea: position.positionArea, - positionIsSelected: position.positionIsSelected, - isSpecial: position.isSpecial, - })), + positions: _position, }; }), );