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

@ -46,7 +46,8 @@ export class ProfileOtherEmployeeController extends Controller {
}
@Get("{profileId}")
public async getOther(@Path() profileId: string) {
public async getOther(@Path() profileId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileId);
const lists = await this.otherRepository.find({
where: { profileEmployeeId: profileId },
});
@ -54,7 +55,11 @@ export class ProfileOtherEmployeeController extends Controller {
}
@Get("history/{otherId}")
public async otherHistory(@Path() otherId: string) {
public async otherHistory(@Path() otherId: string, @Request() req: RequestWithUser) {
const _record = await this.otherRepository.findOneBy({ id: otherId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
const record = await this.otherHistoryRepository.find({
where: { profileOtherId: otherId },
order: { createdAt: "DESC" },
@ -64,16 +69,15 @@ export class ProfileOtherEmployeeController extends Controller {
@Post()
public async newOther(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeOther) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
}
const profile = await this.profileRepository.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 ProfileOther();
@ -101,10 +105,10 @@ export class ProfileOtherEmployeeController extends Controller {
@Body() body: UpdateProfileOther,
@Path() otherId: string,
) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
const record = await this.otherRepository.findOneBy({ id: otherId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.profileEmployeeId)
const history = new ProfileOtherHistory();
@ -129,7 +133,11 @@ export class ProfileOtherEmployeeController extends Controller {
@Delete("{otherId}")
public async deleteOther(@Path() otherId: string, @Request() req: RequestWithUser) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP");
const _record = await this.otherRepository.findOneBy({ id: otherId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
await this.otherHistoryRepository.delete({
profileOtherId: otherId,
});