ดักลำดับขั้นซ้ำ

This commit is contained in:
Bright 2024-03-14 17:05:35 +07:00
parent dee3216e41
commit 5682fb8424

View file

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