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

@ -36,7 +36,8 @@ import { RequestWithUser } from "../middlewares/user";
export class ProfileAssessmentsEmployeeController extends Controller {
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
private profileAssessmentsRepository = AppDataSource.getRepository(ProfileAssessment);
private profileAssessmentsHistoryRepository = AppDataSource.getRepository(ProfileAssessmentHistory);
private profileAssessmentsHistoryRepository =
AppDataSource.getRepository(ProfileAssessmentHistory);
@Get("user")
public async detailProfileAssessmentsUser(@Request() request: { user: Record<string, any> }) {
@ -79,13 +80,44 @@ export class ProfileAssessmentsEmployeeController extends Controller {
],
})
public async detailProfileAssessments(@Path() profileEmployeeId: string) {
const getProfileAssessments = await this.profileAssessmentsRepository.findBy({ profileEmployeeId });
const getProfileAssessments = await this.profileAssessmentsRepository.findBy({
profileEmployeeId,
});
if (!getProfileAssessments) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileAssessments);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async getProfileAssessmentsHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.profileAssessmentsHistoryRepository.find({
relations: {
histories: true,
},
where: {
histories: {
profileEmployeeId: profile.id,
},
},
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Get("history/{assessmentId}")
@Example({
status: 200,