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 == "ทั่วไป" &&