ดักกรณีลบผังลูกจ้าง

This commit is contained in:
Bright 2024-05-29 09:40:02 +07:00
parent b27c61a01f
commit ffcf3b1b73

View file

@ -26,6 +26,7 @@ import HttpStatusCode from "../interfaces/http-status";
import { SalaryRankEmployee } from "../entities/SalaryRankEmployee";
import { randomUUID } from "crypto";
import { Salarys } from "../entities/Salarys";
import { SalaryFormulaEmployee } from "../entities/SalaryFormulaEmployee";
@Route("api/v1/salary/employee")
@Tags("SalaryEmployee")
@ -33,6 +34,8 @@ import { Salarys } from "../entities/Salarys";
export class SalaryEmployeeController extends Controller {
private salaryEmployeeRepository = AppDataSource.getRepository(SalaryEmployee);
private salaryRankEmployeeRepository = AppDataSource.getRepository(SalaryRankEmployee);
private salaryFormulaEmployeeRepository = AppDataSource.getRepository(SalaryFormulaEmployee);
/**
* API (Active)
*
@ -171,6 +174,16 @@ export class SalaryEmployeeController extends Controller {
"ไม่สามารถลบข้อมูลนี้ได้ เนื่องจากเปิดใช้งานอยู่",
);
}
const chk_SalaryFormulaEmp = await this.salaryFormulaEmployeeRepository.find({
where: { salaryEmployeeId: id },
});
if(chk_SalaryFormulaEmp.length > 0){
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่สามารถลบรายการนี้ได้เนื่องจากมีการใช้งานอยู่",
);
}
const del_SalaryRank = await this.salaryRankEmployeeRepository.find({
where: { salaryEmployeeId: chk_Salary.id },
});