role เมนู ลูกจ้างประจำ กทม.

This commit is contained in:
AdisakKanthawilang 2024-08-23 16:28:31 +07:00
parent 359d22beec
commit 7237c68cb8
23 changed files with 327 additions and 155 deletions

View file

@ -68,7 +68,8 @@ export class ProfileHonorEmployeeController extends Controller {
},
],
})
public async getHonor(@Path() profileEmployeeId: string) {
public async getHonor(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const record = await this.honorRepo.findBy({ profileEmployeeId });
return new HttpSuccess(record);
}
@ -133,7 +134,12 @@ export class ProfileHonorEmployeeController extends Controller {
},
],
})
public async honorHistory(@Path() honorId: string) {
public async honorHistory(@Path() honorId: string, @Request() req: RequestWithUser) {
const _record = await this.honorRepo.findOneBy({ id: honorId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
const record = await this.honorHistoryRepo.findBy({
profileHonorId: honorId,
});
@ -142,16 +148,15 @@ export class ProfileHonorEmployeeController extends Controller {
@Post()
public async newHonor(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeHonor) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
}
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id);
const data = new ProfileHonor();
@ -179,11 +184,10 @@ export class ProfileHonorEmployeeController extends Controller {
@Body() body: UpdateProfileHonor,
@Path() honorId: string,
) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
const record = await this.honorRepo.findOneBy({ id: honorId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.profileEmployeeId)
const history = new ProfileHonorHistory();
Object.assign(record, body);
@ -204,7 +208,11 @@ export class ProfileHonorEmployeeController extends Controller {
@Delete("{honorId}")
public async deleteTraning(@Path() honorId: string, @Request() req: RequestWithUser) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP");
const _record = await this.honorRepo.findOneBy({ id: honorId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
await this.honorHistoryRepo.delete({
profileHonorId: honorId,
});