From 3d8b66d3cc9cb84949931900e38c77c4d0dfedd6 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 17 Oct 2024 15:13:59 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=AA=E0=B8=81=E0=B8=88=20=E0=B8=A1?= =?UTF-8?q?=E0=B8=AD=E0=B8=9A=E0=B8=AB=E0=B8=A1=E0=B8=B2=E0=B8=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/WorkflowController.ts | 30 ++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/controllers/WorkflowController.ts b/src/controllers/WorkflowController.ts index c249ca64..e92d8327 100644 --- a/src/controllers/WorkflowController.ts +++ b/src/controllers/WorkflowController.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Get, Post, Request, Route, Security, Tags } from "tsoa"; +import { Body, Controller, Get, Path, Post, Request, Route, Security, Tags } from "tsoa"; import { AppDataSource } from "../database/data-source"; import { RequestWithUser } from "../middlewares/user"; import HttpError from "../interfaces/http-error"; @@ -664,4 +664,32 @@ export class WorkflowController extends Controller { return new HttpSuccess(_posMasters); } + + /** + * API เช็ค สกจ + * + * @summary เช็ค สกจ + * + */ + @Get("keycloak/isofficer/{system}") + async getIsOfficerByKeycloak(@Path() system: string, @Request() req: RequestWithUser) { + const profile = await this.profileRepo.findOne({ + where: { + keycloak: req.user.sub, + }, + }); + if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งาน"); + + const profileOfficer = await this.posMasterRepo.findOne({ + where: { + posMasterAssigns: { assignId: system }, + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + current_holderId: profile.id, + }, + relations: ["orgChild1"], + }); + if (!profileOfficer) return new HttpSuccess({ isOfficer: false, isStaff: false }); + let isOfficer = profileOfficer.orgChild1 == null ? false : profileOfficer.orgChild1.isOfficer; + return new HttpSuccess({ isOfficer: isOfficer, isStaff: !isOfficer }); + } }