From 8a7417edf9c1978f9c57f202dde9a21ff0175745 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 27 Aug 2025 10:38:47 +0700 Subject: [PATCH] =?UTF-8?q?API=20=E0=B8=97=E0=B8=B5=E0=B9=88=E0=B8=95?= =?UTF-8?q?=E0=B9=89=E0=B8=AD=E0=B8=87=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A?= =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82=20=E0=B8=84?= =?UTF-8?q?=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87=E0=B9=82=E0=B8=9B?= =?UTF-8?q?=E0=B8=A3=E0=B8=94=E0=B9=80=E0=B8=81=E0=B8=A5=E0=B9=89=E0=B8=B2?= =?UTF-8?q?=E0=B8=AF=20=E0=B9=81=E0=B8=95=E0=B9=88=E0=B8=87=E0=B8=95?= =?UTF-8?q?=E0=B8=B1=E0=B9=89=E0=B8=87=E0=B9=83=E0=B8=AB=E0=B9=89=E0=B8=94?= =?UTF-8?q?=E0=B8=B3=E0=B8=A3=E0=B8=87=E0=B8=95=E0=B8=B3=E0=B9=81=E0=B8=AB?= =?UTF-8?q?=E0=B8=99=E0=B9=88=E0=B8=87=20#1780?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 11 +++- src/controllers/PositionController.ts | 72 ++++++++++++++++++++------- 2 files changed, 63 insertions(+), 20 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 78bb9be3..c1e98a6c 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -2169,7 +2169,16 @@ export class CommandController extends Controller { command.detailFooter = commandType.detailFooter; command.isAttachment = commandType.isAttachment; command.isUploadAttachment = commandType.isUploadAttachment; - command.status = "NEW"; + // ถ้าเป็นคำสั่งโปรดเกล้าฯ "C-PM-47" ให้เปิดถึงรออัปโหลดไฟล์ #1780 + if (commandCode === "C-PM-47") { + command.isSignature = true; + command.isDraft = true; + command.isSign = true; + command.status = "PENDING"; + } + else { + command.status = "NEW"; + } command.issue = commandType.name; (command.commandAffectDate = requestBody.commandAffectDate ? new Date(requestBody.commandAffectDate) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index e8467d12..2eb86e64 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -4075,21 +4075,53 @@ export class PositionController extends Controller { }, ) { let typeCondition: any = {}; - let conditionA: any = null; + let conditionA: any = "1=1"; + let params: any = {}; + let posType: any = {}; + let posLevel: any = {}; - let posType = await this.posTypeRepository.findOne({ - where: { id: String(body.posType) }, - }); - let posLevel = await this.posLevelRepository.findOne({ - where: { id: String(body.posLevel) }, - }); + if (body.typeCommand === "ROYAL") { + posType = await this.posTypeRepository.find({ + where: { posTypeName: In(["วิชาการ", "บริหาร"]) }, + }); + posLevel = await this.posLevelRepository.find({ + where: { + posTypeId: In(posType.map((x: any) => x.id)), + posLevelName: In(["ทรงคุณวุฒิ", "สูง"]) + }, + }); + conditionA = "positions.posTypeId IN (:...posTypeIds) AND positions.posLevelId IN (:...posLevelIds)"; + params = { + posTypeIds: posType.map((x: any) => x.id), + posLevelIds: posLevel.map((x: any) => x.id), + }; + } + else { + posType = await this.posTypeRepository.findOne({ + where: { id: String(body.posType) }, + }); + posLevel = await this.posLevelRepository.findOne({ + where: { id: String(body.posLevel) }, + }); - if (body.typeCommand == "APPOINTED" || body.typeCommand == "MOVE") { - conditionA = "positions.posTypeId LIKE :posType AND positions.posLevelId LIKE :posLevel"; - } else if (body.typeCommand == "APPOINT") { - conditionA = "posType.posTypeRank > :posTypeRank"; - } else if (body.typeCommand == "SLIP") { - conditionA = "positions.posTypeId LIKE :posType AND posLevel.posLevelRank > :posLevelRank"; + if (body.typeCommand == "APPOINTED" || body.typeCommand == "MOVE") { + conditionA = "positions.posTypeId LIKE :posType AND positions.posLevelId LIKE :posLevel"; + params = { + posType: posType?.id, + posLevel: posLevel?.id, + }; + } else if (body.typeCommand == "APPOINT") { + conditionA = "posType.posTypeRank > :posTypeRank"; + params = { + posTypeRank: posType?.posTypeRank ?? 0, + }; + } else if (body.typeCommand == "SLIP") { + conditionA = "positions.posTypeId LIKE :posType AND posLevel.posLevelRank > :posLevelRank"; + params = { + posType: posType?.id, + posLevelRank: posLevel?.posLevelRank ?? 0, + }; + } } if (body.isAll == false) { @@ -4161,12 +4193,14 @@ export class PositionController extends Controller { .andWhere("posMaster.next_holderId IS NULL") .andWhere( new Brackets((qb) => { - qb.andWhere(typeCondition).andWhere(conditionA == null ? "1=1" : conditionA, { - posType: posType == null ? `%%` : `${posType.id}`, - posLevel: posLevel == null ? `%%` : `${posLevel.id}`, - posTypeRank: posType == null ? 0 : posType.posTypeRank, - posLevelRank: posLevel == null ? 0 : posLevel.posLevelRank, - }); + qb.andWhere(typeCondition) + // .andWhere(conditionA == null ? "1=1" : conditionA, { + // posType: posType == null ? `%%` : `${posType.id}`, + // posLevel: posLevel == null ? `%%` : `${posLevel.id}`, + // posTypeRank: posType == null ? 0 : posType.posTypeRank, + // posLevelRank: posLevel == null ? 0 : posLevel.posLevelRank, + // }); + .andWhere(conditionA, params); }), ) .orderBy("orgRoot.orgRootOrder", "ASC")