API checkRole and history/user
This commit is contained in:
parent
38871bcc80
commit
3167fe271e
7 changed files with 142 additions and 6 deletions
|
|
@ -803,6 +803,29 @@ export class ProfileController extends Controller {
|
|||
return new HttpSuccess(profile);
|
||||
}
|
||||
|
||||
@Get("type")
|
||||
async checkRole(@Request() request: RequestWithUser) {
|
||||
let role: any;
|
||||
const checkProfile = await this.profileRepo.findOne({
|
||||
where: { keycloak: request.user.sub },
|
||||
});
|
||||
role = "OFFICER";
|
||||
if (!checkProfile) {
|
||||
const checkEmployee = await this.profileEmpRepo.findOne({
|
||||
where: { keycloak: request.user.sub },
|
||||
select: ["employeeClass"],
|
||||
});
|
||||
if (checkEmployee?.employeeClass === "PERM" || checkEmployee?.employeeClass === "TEMP") {
|
||||
role = checkEmployee.employeeClass.toUpperCase();
|
||||
} else {
|
||||
role = "EMPLOYEE";
|
||||
}
|
||||
if (!checkProfile && !checkEmployee)
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
|
||||
}
|
||||
return new HttpSuccess(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* API ประวัติการแก้ไขรายการทะเบียนประวัติ
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue