สกจ มอบหมาย

This commit is contained in:
kittapath 2024-10-17 15:13:59 +07:00
parent 41e82a92f9
commit 3d8b66d3cc

View file

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