แก้ลบข้อมูลตำแหน่งขรก./ลูกจ้าง

This commit is contained in:
Bright 2024-06-10 14:02:53 +07:00
parent 288bdb2dff
commit c667f7361f
4 changed files with 89 additions and 53 deletions

View file

@ -139,23 +139,32 @@ export class EmployeePosLevelController extends Controller {
*/
@Delete("{id}")
async deleteType(@Path() id: string) {
const delEmpPosLevel = await this.employeePosLevelRepository.findOne({ where: { id } });
if (!delEmpPosLevel) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงานลูกจ้างประจำนี้");
let result :any
try {
result = await this.employeePosLevelRepository.delete({ id: id });
} catch {
throw new HttpError( HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้เนื่องจากมีการใช้งานระดับชั้นงานนี้อยู่");
}
//ตารางตำแหน่งลูกจ้างประจำ
const EmpPosition = await this.employeePosDictRepository.find({
where: { posLevelId: id },
});
if (EmpPosition.length > 0) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่สามารถลบได้เนื่องจากพบข้อมูลที่ตารางตำแหน่งลูกจ้างประจำ",
);
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
// const delEmpPosLevel = await this.employeePosLevelRepository.findOne({ where: { id } });
// if (!delEmpPosLevel) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงานลูกจ้างประจำนี้");
// }
await this.employeePosLevelRepository.remove(delEmpPosLevel);
// //ตารางตำแหน่งลูกจ้างประจำ
// const EmpPosition = await this.employeePosDictRepository.find({
// where: { posLevelId: id },
// });
// if (EmpPosition.length > 0) {
// throw new HttpError(
// HttpStatusCode.NOT_FOUND,
// "ไม่สามารถลบได้เนื่องจากพบข้อมูลที่ตารางตำแหน่งลูกจ้างประจำ",
// );
// }
// await this.employeePosLevelRepository.remove(delEmpPosLevel);
return new HttpSuccess();
}

View file

@ -134,32 +134,41 @@ export class EmployeePosTypeController extends Controller {
*/
@Delete("{id}")
async deleteType(@Path() id: string) {
const delEmpPosType = await this.employeePosTypeRepository.findOne({ where: { id } });
if (!delEmpPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานลูกจ้างประจำนี้");
let result :any
try {
result = await this.employeePosTypeRepository.delete({ id: id });
} catch {
throw new HttpError( HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้เนื่องจากมีการใช้งานระดับกลุ่มงานนี้อยู่");
}
//ตารางระดับชั้นงาน
const EmpPosLevel = await this.employeePosLevelRepository.find({
where: { posTypeId: id },
});
if (EmpPosLevel.length > 0) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่สามารถลบได้เนื่องจากพบข้อมูลที่ตารางระดับชั้นงาน",
);
}
//ตารางตำแหน่งลูกจ้างประจำ
const EmpPosition = await this.employeePosDictRepository.find({
where: { posTypeId: id },
});
if (EmpPosition.length > 0) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่สามารถลบได้เนื่องจากพบข้อมูลที่ตารางตำแหน่งลูกจ้างประจำ",
);
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
// const delEmpPosType = await this.employeePosTypeRepository.findOne({ where: { id } });
// if (!delEmpPosType) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานลูกจ้างประจำนี้");
// }
// // ตารางระดับชั้นงาน
// const EmpPosLevel = await this.employeePosLevelRepository.find({
// where: { posTypeId: id },
// });
// if (EmpPosLevel.length > 0) {
// throw new HttpError(
// HttpStatusCode.NOT_FOUND,
// "ไม่สามารถลบข้อมูลได้เนื่องจากมีการใช้งานระดับชั้นงานนี้อยู่",
// );
// }
// //ตารางตำแหน่งลูกจ้างประจำ
// const EmpPosition = await this.employeePosDictRepository.find({
// where: { posTypeId: id },
// });
// if (EmpPosition.length > 0) {
// throw new HttpError(
// HttpStatusCode.NOT_FOUND,
// "ไม่สามารถลบได้เนื่องจากพบข้อมูลที่ตารางตำแหน่งลูกจ้างประจำ",
// );
// }
await this.employeePosTypeRepository.remove(delEmpPosType);
// await this.employeePosTypeRepository.remove(delEmpPosType);
return new HttpSuccess();
}

View file

@ -158,11 +158,20 @@ export class PosLevelController extends Controller {
*/
@Delete("{id}")
async deleteLevel(@Path() id: string) {
const delPosLevel = await this.posLevelRepository.findOne({ where: { id } });
if (!delPosLevel) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
let result :any
try {
result = await this.posLevelRepository.delete({ id: id });
} catch {
throw new HttpError( HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้เนื่องจากมีการใช้งานระดับตำแหน่งนี้อยู่");
}
await this.posLevelRepository.remove(delPosLevel);
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
// const delPosLevel = await this.posLevelRepository.findOne({ where: { id } });
// if (!delPosLevel) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
// }
// await this.posLevelRepository.remove(delPosLevel);
return new HttpSuccess();
}

View file

@ -118,21 +118,30 @@ export class PosTypeController extends Controller {
*/
@Delete("{id}")
async deleteType(@Path() id: string) {
const delPosType = await this.posTypeRepository.findOne({ where: { id } });
if (!delPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
let result :any
try {
result = await this.posTypeRepository.delete({ id: id });
} catch {
throw new HttpError( HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้เนื่องจากมีการใช้งานประเภทตำแหน่งนี้อยู่");
}
const IdExitsInLevel = await this.posLevelRepository.find({
where: { posTypeId: id },
});
if (IdExitsInLevel.length > 0) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่สามารถลบได้เนื่องจากพบข้อมูลที่ตารางระดับตำแหน่ง",
);
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
// const delPosType = await this.posTypeRepository.findOne({ where: { id } });
// if (!delPosType) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
// }
// const IdExitsInLevel = await this.posLevelRepository.find({
// where: { posTypeId: id },
// });
// if (IdExitsInLevel.length > 0) {
// throw new HttpError(
// HttpStatusCode.NOT_FOUND,
// "ไม่สามารถลบได้เนื่องจากพบข้อมูลที่ตารางระดับตำแหน่ง",
// );
// }
await this.posTypeRepository.remove(delPosType);
// await this.posTypeRepository.remove(delPosType);
return new HttpSuccess();
}