API checkRole and history/user
This commit is contained in:
parent
38871bcc80
commit
3167fe271e
7 changed files with 142 additions and 6 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue