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);