From e4248c09f893cc8f2439c98bb9ec958fb7498434 Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Mon, 18 Mar 2024 13:28:48 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=E0=B9=80=E0=B8=87=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=99=E0=B9=84?= =?UTF-8?q?=E0=B8=82=20posTypeRank?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/EmployeePosTypeController.ts | 28 +++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) 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);