From ae3a63459578220b120dc1da29574eb87aa2b26f Mon Sep 17 00:00:00 2001 From: harid Date: Wed, 21 Jan 2026 13:53:29 +0700 Subject: [PATCH] =?UTF-8?q?Task=20#2208=20=E0=B8=81=E0=B8=A3=E0=B8=93?= =?UTF-8?q?=E0=B8=B5=E0=B8=82=E0=B8=AD=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84?= =?UTF-8?q?=E0=B8=82=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=A1=E0=B8=B9=E0=B8=A5?= =?UTF-8?q?=E0=B8=97=E0=B8=B0=E0=B9=80=E0=B8=9A=E0=B8=B5=E0=B8=A2=E0=B8=99?= =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95=E0=B8=B4?= =?UTF-8?q?=20=E0=B9=81=E0=B8=A5=E0=B8=B0=20IDP=20=E0=B9=81=E0=B8=A5?= =?UTF-8?q?=E0=B8=B0=E0=B8=84=E0=B8=99=E0=B8=82=E0=B8=AD=E0=B8=AD=E0=B8=A2?= =?UTF-8?q?=E0=B8=B9=E0=B9=88=E0=B9=83=E0=B8=99=E0=B8=AA=E0=B8=B3=E0=B8=99?= =?UTF-8?q?=E0=B8=B1=E0=B8=81=E0=B8=9B=E0=B8=A5=E0=B8=B1=E0=B8=94=E0=B8=81?= =?UTF-8?q?=E0=B8=A3=E0=B8=B8=E0=B8=87=E0=B9=80=E0=B8=97=E0=B8=9E=E0=B8=A1?= =?UTF-8?q?=E0=B8=AB=E0=B8=B2=E0=B8=99=E0=B8=84=E0=B8=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevelopmentRequestController.ts | 27 ++++++++++++++++-- src/controllers/ProfileEditController.ts | 28 +++++++++++++++++-- src/controllers/WorkflowController.ts | 22 +++++++++++---- 3 files changed, 66 insertions(+), 11 deletions(-) diff --git a/src/controllers/DevelopmentRequestController.ts b/src/controllers/DevelopmentRequestController.ts index 16288640..f02b3049 100644 --- a/src/controllers/DevelopmentRequestController.ts +++ b/src/controllers/DevelopmentRequestController.ts @@ -27,6 +27,7 @@ import { ProfileDevelopmentHistory } from "../entities/ProfileDevelopmentHistory import { setLogDataDiff } from "../interfaces/utils"; import CallAPI from "../interfaces/call-api"; import { OrgRevision } from "../entities/OrgRevision"; +import { OrgRoot } from "../entities/OrgRoot"; @Route("api/v1/org/profile/development-request") @Tags("DevelopmentRequest") @Security("bearerAuth") @@ -37,6 +38,7 @@ export class DevelopmentRequestController extends Controller { private developmentProjectRepository = AppDataSource.getRepository(DevelopmentProject); private developmentHistoryRepository = AppDataSource.getRepository(ProfileDevelopmentHistory); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); + private orgRootRepo = AppDataSource.getRepository(OrgRoot); @Get("user") public async getDevelopmentRequestUser( @@ -298,12 +300,32 @@ export class DevelopmentRequestController extends Controller { @Body() body: CreateDevelopmentRequest, ) { const profile = await this.profileRepository.findOne({ - where: { keycloak: req.user.sub }, - relations: ["posLevel", "posType"], + relations: { + posLevel: true, + posType: true, + current_holders: true + }, + where: { + keycloak: req.user.sub, + current_holders: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + } + } }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } + const orgRoot = await this.orgRootRepo.findOne({ + select: { + isDeputy: true + }, + where: { + id: profile.current_holders.find(x => x.orgRootId)!.orgRootId ?? "" + } + }) const before = null; const data = new DevelopmentRequest(); @@ -346,6 +368,7 @@ export class DevelopmentRequestController extends Controller { posLevelName: profile.posLevel.posLevelName, posTypeName: profile.posType.posTypeName, fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`, + isDeputy: orgRoot?.isDeputy ?? false }) .catch((error) => { console.error("Error calling API:", error); diff --git a/src/controllers/ProfileEditController.ts b/src/controllers/ProfileEditController.ts index 4c4fc6b8..013a2e9d 100644 --- a/src/controllers/ProfileEditController.ts +++ b/src/controllers/ProfileEditController.ts @@ -23,7 +23,7 @@ import { Brackets } from "typeorm"; import CallAPI from "../interfaces/call-api"; import permission from "../interfaces/permission"; import { OrgRevision } from "../entities/OrgRevision"; - +import { OrgRoot } from "../entities/OrgRoot"; @Route("api/v1/org/profile/edit") @Tags("ProfileEdit") @Security("bearerAuth") @@ -31,6 +31,7 @@ export class ProfileEditController extends Controller { private profileRepo = AppDataSource.getRepository(Profile); private profileEditRepo = AppDataSource.getRepository(ProfileEdit); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); + private orgRootRepo = AppDataSource.getRepository(OrgRoot); @Get("user") public async detailProfileEditUser( @@ -294,12 +295,32 @@ export class ProfileEditController extends Controller { @Post() public async newProfileEdit(@Request() req: RequestWithUser, @Body() body: CreateProfileEdit) { const profile = await this.profileRepo.findOne({ - where: { keycloak: req.user.sub }, - relations: ["posLevel", "posType"], + relations: { + posLevel: true, + posType: true, + current_holders: true + }, + where: { + keycloak: req.user.sub, + current_holders: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + } + } }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } + const orgRoot = await this.orgRootRepo.findOne({ + select: { + isDeputy: true + }, + where: { + id: profile.current_holders.find(x => x.orgRootId)!.orgRootId ?? "" + } + }) const data = new ProfileEdit(); const meta = { @@ -322,6 +343,7 @@ export class ProfileEditController extends Controller { posLevelName: profile.posLevel.posLevelName, posTypeName: profile.posType.posTypeName, fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`, + isDeputy: orgRoot?.isDeputy ?? false }) .catch((error) => { console.error("Error calling API:", error); diff --git a/src/controllers/WorkflowController.ts b/src/controllers/WorkflowController.ts index 12688f80..f02aaf4b 100644 --- a/src/controllers/WorkflowController.ts +++ b/src/controllers/WorkflowController.ts @@ -145,12 +145,22 @@ export class WorkflowController extends Controller { metaStates.find((metaState) => metaState.id === metaStateOp.metaStateId)?.order === state.order, ); - // Task #2207 กรณีคนขอโอนอยู่ในสำนักปลัดกรุงเทพมหานคร - if (body.isDeputy && metaStateOp.operator == "PersonnelOfficer" && correspondingState?.order == 1) { - return; - } - else if (body.isDeputy && metaStateOp.operator == "Officer" && [1, 2].includes(correspondingState?.order as number)) { - metaStateOp.operator = "PersonnelOfficer" + if (body.isDeputy) { + // Task #2207 กรณีคนขอโอนอยู่ในสำนักปลัดกรุงเทพมหานคร + if (body.sysName == "SYS_TRANSFER_REQ") { + if (metaStateOp.operator == "PersonnelOfficer" && correspondingState?.order == 1) { + return; + } + else if (metaStateOp.operator == "Officer" && [1, 2].includes(correspondingState?.order as number)) { + metaStateOp.operator = "PersonnelOfficer" + } + } + // Task #2208 กรณีขอแก้ไขข้อมูลทะเบียนประวัติ และ IDP และคนขออยู่ในสำนักปลัดกรุงเทพมหานคร + if (metaStateOp.operator == "Officer" && + (["REGISTRY_PROFILE", "REGISTRY_PROFILE_EMP", "REGISTRY_IDP"].includes(body.sysName)) + ) { + metaStateOp.operator = "PersonnelOfficer" + } } if (correspondingState) { const stateOperator = new StateOperator();