diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 52de0922..80859692 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -19,6 +19,7 @@ import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; +import HttpStatusCode from "../interfaces/http-status"; import { Brackets, Double, In, IsNull, Like, Not } from "typeorm"; import { OrgRevision } from "../entities/OrgRevision"; import { @@ -2039,9 +2040,13 @@ export class ProfileEmployeeController extends Controller { if (!result) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } - await new permission().PermissionOrgUserDelete(request, "SYS_REGISTRY_EMP", result.id); - await this.informationHistoryRepository.delete({ profileEmployeeId: id }); - await this.profileRepo.remove(result); + try{ + await new permission().PermissionOrgUserDelete(request, "SYS_REGISTRY_EMP", result.id); + await this.informationHistoryRepository.delete({ profileEmployeeId: id }); + await this.profileRepo.remove(result); + } catch { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบข้อมูลได้"); + } return new HttpSuccess(); } diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index 6dc49b1a..ec89872b 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -69,6 +69,7 @@ import axios from "axios"; import { deleteUser } from "../keycloak"; import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory"; import { getTopDegrees } from "../services/PositionService"; +import HttpStatusCode from "../interfaces/http-status"; @Route("api/v1/org/profile-temp") @Tags("ProfileEmployee") @Security("bearerAuth") @@ -1027,8 +1028,13 @@ export class ProfileEmployeeTempController extends Controller { if (!result) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } - await this.informationHistoryRepository.delete({ profileEmployeeId: id }); - await this.profileRepo.remove(result); + + try{ + await this.informationHistoryRepository.delete({ profileEmployeeId: id }); + await this.profileRepo.remove(result); + } catch { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบข้อมูลได้"); + } return new HttpSuccess(); }