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

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

@ -61,7 +61,7 @@ export class ProvinceController extends Controller {
relations: { districts: true },
});
if (!_province) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางจังหวัดนี้");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดนี้");
}
return new HttpSuccess(_province);
@ -81,7 +81,7 @@ export class ProvinceController extends Controller {
) {
const _province = Object.assign(new Province(), requestBody);
if (!_province) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางจังหวัดนี้");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดนี้");
}
const checkName = await this.provinceRepository.findOne({
@ -116,7 +116,7 @@ export class ProvinceController extends Controller {
) {
const _province = await this.provinceRepository.findOne({ where: { id: id } });
if (!_province) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางจังหวัดนี้");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดนี้");
}
const checkName = await this.provinceRepository.findOne({
where: { id: Not(id), name: requestBody.name },
@ -145,14 +145,17 @@ export class ProvinceController extends Controller {
// where: { id: id },
// });
// if (!_delProvince) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางจังหวัดนี้");
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดนี้");
// }
// await this.provinceRepository.delete(_delProvince.id);
let result :any
let result: any;
try {
result = await this.provinceRepository.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, "ไม่พบข้อมูล");