Fix District/subDistrict
This commit is contained in:
parent
27fefee8d7
commit
20ccb3f26d
4 changed files with 57 additions and 17 deletions
|
|
@ -18,6 +18,7 @@ import HttpSuccess from "../interfaces/http-success";
|
|||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { District, CreateDistrict, UpdateDistrict } from "../entities/District";
|
||||
import { Province } from "../entities/Province";
|
||||
import { Not } from "typeorm";
|
||||
|
||||
@Route("api/v1/org/metadata/district")
|
||||
|
|
@ -30,6 +31,7 @@ import { Not } from "typeorm";
|
|||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class DistrictController extends Controller {
|
||||
private districtRepository = AppDataSource.getRepository(District);
|
||||
private provinceRepository = AppDataSource.getRepository(Province);
|
||||
|
||||
/**
|
||||
* API list รายการเขต
|
||||
|
|
@ -84,6 +86,13 @@ export class DistrictController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้");
|
||||
}
|
||||
|
||||
const chkProvince = await this.provinceRepository.findOne({
|
||||
where: { id: requestBody.provinceId }
|
||||
})
|
||||
if(!chkProvince){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางจังหวัดนี้");
|
||||
}
|
||||
|
||||
const checkName = await this.districtRepository.findOne({
|
||||
where: { name: requestBody.name },
|
||||
});
|
||||
|
|
@ -118,6 +127,14 @@ export class DistrictController extends Controller {
|
|||
if (!_district) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้");
|
||||
}
|
||||
|
||||
const chkProvince = await this.provinceRepository.findOne({
|
||||
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 },
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue