From e570339e1a8d9b820e70ffe9ad59f62cf9d1d3d2 Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 18 Mar 2025 15:14:27 +0700 Subject: [PATCH] =?UTF-8?q?list=20=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=8A?= =?UTF-8?q?=E0=B8=B7=E0=B9=88=E0=B8=AD=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/WorkflowController.ts | 50 +++++++++++++++------------ 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/controllers/WorkflowController.ts b/src/controllers/WorkflowController.ts index a1a7207c..1e305874 100644 --- a/src/controllers/WorkflowController.ts +++ b/src/controllers/WorkflowController.ts @@ -800,27 +800,28 @@ export class WorkflowController extends Controller { keyword: string; page: number; pageSize: number; + profileId?: string | null; }, ) { - let userId = ""; - // if (xxx) { - // } else { - // const posMasterUser = await this.posMasterRepo.findOne({ - // where: { - // orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, - // current_holder: { keycloak: request.user.sub }, - // }, - // relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"], - // }); - // } + let posMasterUser: PosMaster = new PosMaster(); + if (body.profileId) { + posMasterUser = (await this.posMasterRepo.findOne({ + where: { + orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + current_holderId: body.profileId, + }, + relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"], + })) as PosMaster; + } else { + posMasterUser = (await this.posMasterRepo.findOne({ + where: { + orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + current_holder: { keycloak: request.user.sub }, + }, + relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"], + })) as PosMaster; + } - const posMasterUser = await this.posMasterRepo.findOne({ - where: { - orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, - current_holder: { keycloak: request.user.sub }, - }, - relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"], - }); if (!posMasterUser || !posMasterUser.orgRootId) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบตำแหน่งผู้ใช้งาน"); @@ -846,10 +847,15 @@ export class WorkflowController extends Controller { // orgChild3Id: IsNull(), // orgChild4Id: IsNull(), }; - condition.orgChild1Id = IsNull(); - condition.orgChild2Id = IsNull(); - condition.orgChild3Id = IsNull(); - condition.orgChild4Id = IsNull(); + if (posMasterUser.orgChild4Id == null) { + condition.orgChild4Id = IsNull(); + } else if (posMasterUser.orgChild3Id == null) { + condition.orgChild3Id = IsNull(); + } else if (posMasterUser.orgChild2Id == null) { + condition.orgChild2Id = IsNull(); + } else if (posMasterUser.orgChild1Id == null) { + condition.orgChild1Id = IsNull(); + } } else { if ( (posMasterUser.current_holder.posType.posTypeName == "ทั่วไป" &&