ไม่พบข้อมูลเขต

This commit is contained in:
Kittapath 2024-06-11 10:55:23 +07:00
parent aa67674fa7
commit 4564912b5b
6 changed files with 157 additions and 52 deletions

View file

@ -63,7 +63,7 @@ export class DistrictController extends Controller {
relations: { subDistricts: true },
});
if (!_district) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเขตนี้");
}
return new HttpSuccess(_district);
@ -83,14 +83,14 @@ export class DistrictController extends Controller {
) {
const _district = Object.assign(new District(), requestBody);
if (!_district) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเขตนี้");
}
const chkProvince = await this.provinceRepository.findOne({
where: { id: requestBody.provinceId }
})
if(!chkProvince){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางจังหวัดนี้");
where: { id: requestBody.provinceId },
});
if (!chkProvince) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดนี้");
}
const checkName = await this.districtRepository.findOne({
@ -125,16 +125,16 @@ export class DistrictController extends Controller {
) {
const _district = await this.districtRepository.findOne({ where: { id: id } });
if (!_district) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเขตนี้");
}
const chkProvince = await this.provinceRepository.findOne({
where: { id: requestBody.provinceId }
})
if(!chkProvince){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางจังหวัดนี้");
where: { id: requestBody.provinceId },
});
if (!chkProvince) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดนี้");
}
const checkName = await this.districtRepository.findOne({
where: { id: Not(id), name: requestBody.name },
});
@ -162,14 +162,17 @@ export class DistrictController extends Controller {
// where: { id: id },
// });
// if (!_delDistrict) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้");
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเขตนี้");
// }
// await this.districtRepository.delete(_delDistrict.id);
let result :any
let result: any;
try {
result = await this.districtRepository.delete({ id: id });
} catch {
throw new HttpError( HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้เนื่องจากมีการใช้งานข้อมูลเขต/อำเภอนี้อยู่");
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่สามารถลบได้เนื่องจากมีการใช้งานข้อมูลเขต/อำเภอนี้อยู่",
);
}
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");