เช็คอักษรย่อซ้ำ

This commit is contained in:
Kittapath 2024-04-26 18:37:54 +07:00
parent 815ed1b04f
commit 73deeaab66
2 changed files with 68 additions and 57 deletions

View file

@ -117,7 +117,10 @@ export class OrgRootController extends Controller {
}
const chkShort = await this.orgRootRepository.findOne({
where: { orgRevisionId: requestBody.orgRevisionId, orgRootShortName: requestBody.orgRootShortName },
where: {
orgRevisionId: requestBody.orgRevisionId,
orgRootShortName: requestBody.orgRootShortName,
},
});
if (chkShort != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้มีอยู่ในระบบแล้ว");
@ -199,16 +202,24 @@ export class OrgRootController extends Controller {
}
const chkCode = await this.orgRootRepository.findOne({
where: { orgRevisionId: requestBody.orgRevisionId, orgRootCode: requestBody.orgRootCode },
where: {
orgRevisionId: requestBody.orgRevisionId,
orgRootCode: requestBody.orgRootCode,
id: Not(id),
},
});
if (chkCode?.id != id && chkCode != null) {
if (chkCode != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
const chkShort = await this.orgRootRepository.findOne({
where: { orgRevisionId: requestBody.orgRevisionId, orgRootShortName: requestBody.orgRootShortName },
where: {
orgRevisionId: requestBody.orgRevisionId,
orgRootShortName: requestBody.orgRootShortName,
id: Not(id),
},
});
if (chkCode?.id != id && chkShort != null) {
if (chkShort != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้มีอยู่ในระบบแล้ว");
}
@ -217,26 +228,26 @@ export class OrgRootController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้างระดับ Root นี้");
}
const chkCodeChild1 = await this.orgChild1Repository.findOne({
where:{
orgRevisionId : requestBody.orgRevisionId,
orgRootId: id,
orgChild1Code: requestBody.orgRootCode,
}
});
if(chkCodeChild1 != null){
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้ซ้ำกับรหัสส่วนราชการ");
}
const chkShortChild1 = await this.orgChild1Repository.findOne({
where:{
orgRevisionId : requestBody.orgRevisionId,
orgRootId: id,
orgChild1ShortName: requestBody.orgRootShortName,
}
});
if(chkShortChild1 != null){
throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้ซ้ำกับอักษรย่อส่วนราชการ");
}
// const chkCodeChild1 = await this.orgChild1Repository.findOne({
// where:{
// orgRevisionId : requestBody.orgRevisionId,
// orgRootId: id,
// orgChild1Code: requestBody.orgRootCode,
// }
// });
// if(chkCodeChild1 != null){
// throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้ซ้ำกับรหัสส่วนราชการ");
// }
// const chkShortChild1 = await this.orgChild1Repository.findOne({
// where:{
// orgRevisionId : requestBody.orgRevisionId,
// orgRootId: id,
// orgChild1ShortName: requestBody.orgRootShortName,
// }
// });
// if(chkShortChild1 != null){
// throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้ซ้ำกับอักษรย่อส่วนราชการ");
// }
orgRoot.lastUpdateUserId = request.user.sub;
orgRoot.lastUpdateFullName = request.user.name;
@ -296,7 +307,7 @@ export class OrgRootController extends Controller {
const empPositions = await this.empPositionRepository.find({
where: [{ posMasterId: In(empPosMasters.map((x) => x.id)) }],
});
await this.empPositionRepository.remove(empPositions);
await this.empPosMasterRepository.remove(empPosMasters);
await this.positionRepository.remove(positions);