From 5682fb8424e673ad4a34f120fef59cb3fd1f38ca Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 14 Mar 2024 17:05:35 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=94=E0=B8=B1=E0=B8=81=E0=B8=A5=E0=B8=B3?= =?UTF-8?q?=E0=B8=94=E0=B8=B1=E0=B8=9A=E0=B8=82=E0=B8=B1=E0=B9=89=E0=B8=99?= =?UTF-8?q?=E0=B8=8B=E0=B9=89=E0=B8=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SalaryRankEmployeeController.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/controllers/SalaryRankEmployeeController.ts b/src/controllers/SalaryRankEmployeeController.ts index ae5dacc..e09994b 100644 --- a/src/controllers/SalaryRankEmployeeController.ts +++ b/src/controllers/SalaryRankEmployeeController.ts @@ -14,6 +14,7 @@ import { Get, Query, } from "tsoa"; +import { Not } from "typeorm"; import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; import HttpStatusCode from "../interfaces/http-status"; @@ -54,6 +55,15 @@ export class SalaryRankEmployeeController extends Controller { if (!checkSalary) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้"); } + const checkStep = await this.salaryRankEmployeeRepository.find({ + where: { + step: requestBody.step, + salaryEmployeeId: requestBody.salaryEmployeeId + } + }); + if(checkStep.length > 0){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถเพิ่มได้ เนื่องจากลำดับขั้นนี้ซ้ำ"); + } const salaryRankEmployee = Object.assign(new SalaryRankEmployee(), requestBody); salaryRankEmployee.createdUserId = request.user.sub; salaryRankEmployee.createdFullName = request.user.name; @@ -85,6 +95,16 @@ export class SalaryRankEmployeeController extends Controller { if (!salaryRankEmployee) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับผังเงินเดือนนี้"); } + const checkStep = await this.salaryRankEmployeeRepository.find({ + where: { + id: Not(id), + step: requestBody.step, + salaryEmployeeId: salaryRankEmployee.salaryEmployeeId + } + }); + if(checkStep.length > 0){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถแก้ไขได้ เนื่องจากลำดับขั้นนี้ซ้ำ"); + } salaryRankEmployee.lastUpdateUserId = request.user.sub; salaryRankEmployee.lastUpdateFullName = request.user.name; this.salaryRankEmployeeRepository.merge(salaryRankEmployee, requestBody);