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

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, "ไม่พบข้อมูล");

View file

@ -63,7 +63,7 @@ export class GenderController extends Controller {
select: ["id", "name"],
});
if (!_gender) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเพศนี้");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเพศนี้");
}
return new HttpSuccess(_gender);
@ -83,7 +83,7 @@ export class GenderController extends Controller {
) {
const _gender = Object.assign(new Gender(), requestBody);
if (!_gender) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเพศนี้");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเพศนี้");
}
const checkName = await this.genderRepository.findOne({
@ -118,7 +118,7 @@ export class GenderController extends Controller {
) {
const _gender = await this.genderRepository.findOne({ where: { id: id } });
if (!_gender) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเพศนี้");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเพศนี้");
}
const checkName = await this.genderRepository.findOne({
where: { id: Not(id), name: requestBody.name },
@ -147,7 +147,7 @@ export class GenderController extends Controller {
where: { id: id },
});
if (!_delGender) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเพศนี้");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเพศนี้");
}
await this.genderRepository.delete(_delGender.id);
return new HttpSuccess();

View file

@ -1041,14 +1041,6 @@ export class ProfileController extends Controller {
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.andWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? queryLike
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
)
.andWhere(
posType != undefined && posType != null && posType != ""
? "posType.posTypeName LIKE :keyword1"
@ -1077,6 +1069,14 @@ export class ProfileController extends Controller {
: `profile.dateRetire IS NOT NULL`
: "1=1",
)
.andWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? queryLike
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
)
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();

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, "ไม่พบข้อมูล");

View file

@ -62,7 +62,7 @@ export class SubDistrictController extends Controller {
select: ["id", "name"],
});
if (!_subDistrict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางแขวงนี้");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแขวงนี้");
}
return new HttpSuccess(_subDistrict);
@ -82,20 +82,20 @@ export class SubDistrictController extends Controller {
) {
const _subDistrict = Object.assign(new SubDistrict(), requestBody);
if (!_subDistrict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางแขวงนี้");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแขวงนี้");
}
const chkDistrict = await this.districtRepository.findOne({
where: { id: requestBody.districtId }
})
where: { id: requestBody.districtId },
});
if (!chkDistrict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเขตนี้");
}
const checkName = await this.subDistrictRepository.findOne({
where: {
name: requestBody.name,
districtId: requestBody.districtId
where: {
name: requestBody.name,
districtId: requestBody.districtId,
},
});
@ -127,21 +127,21 @@ export class SubDistrictController extends Controller {
) {
const _subDistrict = await this.subDistrictRepository.findOne({ where: { id: id } });
if (!_subDistrict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางแขวงนี้");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแขวงนี้");
}
const chkDistrict = await this.districtRepository.findOne({
where: { id: requestBody.districtId }
})
where: { id: requestBody.districtId },
});
if (!chkDistrict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเขตนี้");
}
const checkName = await this.subDistrictRepository.findOne({
where: {
id: Not(id),
where: {
id: Not(id),
name: requestBody.name,
districtId: requestBody.districtId
districtId: requestBody.districtId,
},
});
if (checkName) {
@ -168,14 +168,17 @@ export class SubDistrictController extends Controller {
// where: { id: id },
// });
// if (!_delSubDistrict) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางแขวงนี้");
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแขวงนี้");
// }
// await this.subDistrictRepository.delete(_delSubDistrict.id);
let result :any
let result: any;
try {
result = await this.subDistrictRepository.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, "ไม่พบข้อมูล");