diff --git a/src/controllers/SalaryEmployeeController.ts b/src/controllers/SalaryEmployeeController.ts index 224177f..71e6bd6 100644 --- a/src/controllers/SalaryEmployeeController.ts +++ b/src/controllers/SalaryEmployeeController.ts @@ -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 }, });