role เมนู ข้าราชการ กทม. สามัญ

This commit is contained in:
AdisakKanthawilang 2024-08-22 17:25:25 +07:00
parent edad154826
commit 4b42b896fa
22 changed files with 307 additions and 157 deletions

View file

@ -78,7 +78,11 @@ export class ProfileAssessmentsController extends Controller {
},
],
})
public async detailProfileAssessments(@Path() profileId: string) {
public async detailProfileAssessments(
@Path() profileId: string,
@Request() req: RequestWithUser,
) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const getProfileAssessments = await this.profileAssessmentsRepository.findBy({ profileId });
if (!getProfileAssessments) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -129,7 +133,10 @@ export class ProfileAssessmentsController extends Controller {
},
],
})
public async getProfileAssessmentsHistory(@Path() assessmentId: string) {
public async getProfileAssessmentsHistory(
@Path() assessmentId: string,
@Request() req: RequestWithUser,
) {
const record = await this.profileAssessmentsHistoryRepository.findBy({
profileAssessmentId: assessmentId,
});
@ -137,7 +144,14 @@ export class ProfileAssessmentsController extends Controller {
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
const _record = await this.profileAssessmentsRepository.findOne({
where: {
id: assessmentId,
},
});
if (_record) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_OFFICER", _record.profileId);
}
return new HttpSuccess(record);
}
@ -146,15 +160,15 @@ export class ProfileAssessmentsController extends Controller {
@Request() req: RequestWithUser,
@Body() body: CreateProfileAssessment,
) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_OFFICER");
if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
}
const profile = await this.profileRepo.findOneBy({ id: body.profileId });
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_OFFICER", profile.id);//ตส
const data = new ProfileAssessment();
const meta = {
@ -180,10 +194,11 @@ export class ProfileAssessmentsController extends Controller {
@Request() req: RequestWithUser,
@Path() assessmentId: string,
) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_OFFICER");
const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const history = new ProfileAssessmentHistory();
Object.assign(record, body);
@ -210,7 +225,10 @@ export class ProfileAssessmentsController extends Controller {
@Path() assessmentId: string,
@Request() req: RequestWithUser,
) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_OFFICER");
const _record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", _record.profileId);
}
await this.profileAssessmentsHistoryRepository.delete({
profileAssessmentId: assessmentId,
});