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 }); + } }