diff --git a/src/controllers/EmployeePosTypeController.ts b/src/controllers/EmployeePosTypeController.ts index 2dc61fa3..03bd9dd6 100644 --- a/src/controllers/EmployeePosTypeController.ts +++ b/src/controllers/EmployeePosTypeController.ts @@ -38,7 +38,6 @@ export class EmployeePosTypeController extends Controller { private employeePosDictRepository = AppDataSource.getRepository(EmployeePosDict); private employeePosTypeRepository = AppDataSource.getRepository(EmployeePosType); private employeePosLevelRepository = AppDataSource.getRepository(EmployeePosLevel); - /** * API เพิ่มกลุ่มงานลูกจ้างประจำ * @@ -52,9 +51,6 @@ export class EmployeePosTypeController extends Controller { @Request() request: { user: Record }, ) { const EmpPosType = Object.assign(new EmployeePosType(), requestBody); - if (!EmpPosType) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); - } const chkEmpPosTypeName = await this.employeePosTypeRepository.findOne({ where: { @@ -64,6 +60,18 @@ export class EmployeePosTypeController extends Controller { if (chkEmpPosTypeName) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อกลุ่มงานลูกจ้างประจำนี้มีอยู่ในระบบแล้ว"); } + + const posTypeRank = await this.employeePosTypeRepository.findOne({ + where: { + posTypeRank: requestBody.posTypeRank, + }, + }); + if (posTypeRank) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ระดับของกลุ่มงานลูกจ้างประจำนี้มีอยู่ในระบบแล้ว", + ); + } EmpPosType.createdUserId = request.user.sub; EmpPosType.createdFullName = request.user.name; EmpPosType.lastUpdateUserId = request.user.sub; @@ -98,6 +106,18 @@ export class EmployeePosTypeController extends Controller { if (chkEmpPosType) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อกลุ่มงานลูกจ้างประจำนี้มีอยู่ในระบบแล้ว"); } + const posTypeRank = await this.employeePosTypeRepository.findOne({ + where: { + id: Not(id), + posTypeRank: requestBody.posTypeRank, + }, + }); + if (posTypeRank) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ระดับของกลุ่มงานลูกจ้างประจำนี้มีอยู่ในระบบแล้ว", + ); + } EmpPosType.lastUpdateUserId = request.user.sub; EmpPosType.lastUpdateFullName = request.user.name; this.employeePosTypeRepository.merge(EmpPosType, requestBody);