แก้ลบข้อมูลจังหวัด/อำเภอ

This commit is contained in:
Bright 2024-06-10 14:30:59 +07:00
parent c667f7361f
commit 580e53809d
2 changed files with 30 additions and 12 deletions

View file

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

View file

@ -141,13 +141,22 @@ export class ProvinceController extends Controller {
*/
@Delete("{id}")
async Delete(@Path() id: string) {
const _delProvince = await this.provinceRepository.findOne({
where: { id: id },
});
if (!_delProvince) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางจังหวัดนี้");
// const _delProvince = await this.provinceRepository.findOne({
// where: { id: id },
// });
// if (!_delProvince) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางจังหวัดนี้");
// }
// await this.provinceRepository.delete(_delProvince.id);
let result :any
try {
result = await this.provinceRepository.delete({ id: id });
} catch {
throw new HttpError( HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้เนื่องจากมีการใช้งานข้อมูลจังหวัดนี้อยู่");
}
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
await this.provinceRepository.delete(_delProvince.id);
return new HttpSuccess();
}
}