API checkRole and history/user

This commit is contained in:
AdisakKanthawilang 2024-05-27 11:36:55 +07:00
parent 38871bcc80
commit 3167fe271e
7 changed files with 142 additions and 6 deletions

View file

@ -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
*