diff --git a/src/controllers/WorkflowController.ts b/src/controllers/WorkflowController.ts index 236fdcac..cf7cbd36 100644 --- a/src/controllers/WorkflowController.ts +++ b/src/controllers/WorkflowController.ts @@ -922,7 +922,8 @@ export class WorkflowController extends Controller { }, relations: ["orgChild1"], }); - if (!profileOfficer) return new HttpSuccess({ isOfficer: false, isStaff: false }); + if (!profileOfficer) + return new HttpSuccess({ isOfficer: false, isStaff: false, isDirector: false }); let isOfficer = profileOfficer.orgChild1 == null ? false : profileOfficer.orgChild1.isOfficer; return new HttpSuccess({ isOfficer: isOfficer, @@ -931,6 +932,40 @@ export class WorkflowController extends Controller { }); } + /** + * API เช็ค สกจ + * + * @summary เช็ค สกจ + * + */ + @Get("keycloak/isofficer-root/{system}") + async getIsOfficerByKeycloakRoot(@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, isDirector: false }); + let isOfficer = profileOfficer.orgChild1 == null ? false : profileOfficer.orgChild1.isOfficer; + return new HttpSuccess({ + isOfficer: isOfficer, + isStaff: !isOfficer, + isDirector: + !profileOfficer.orgChild1Id && profileOfficer.orgRootId ? profileOfficer.isDirector : false, + }); + } + /** * API เช็ค สกจ *