diff --git a/src/controllers/OrgChild1Controller.ts b/src/controllers/OrgChild1Controller.ts index 245771e4..52f63ce6 100644 --- a/src/controllers/OrgChild1Controller.ts +++ b/src/controllers/OrgChild1Controller.ts @@ -136,22 +136,22 @@ export class OrgChild1Controller { ); } const chkShort = await this.child1Repository.findOne({ - where: { - orgRevisionId: rootIdExits.orgRevisionId, + where: { + orgRevisionId: rootIdExits.orgRevisionId, orgRootId: requestBody.orgRootId, - orgChild1ShortName: requestBody.orgChild1ShortName + orgChild1ShortName: requestBody.orgChild1ShortName, }, }); if (chkShort != null) { throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้มีอยู่ในระบบแล้ว"); } - if(requestBody.orgChild1Code == rootIdExits.orgRootCode){ - throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสส่วนราชการนี้ซ้ำกับรหัสหน่วยงาน"); - } - if(requestBody.orgChild1ShortName == rootIdExits.orgRootShortName){ - throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้ซ้ำกับอักษรย่อหน่วยงาน"); - } + // if (requestBody.orgChild1Code == rootIdExits.orgRootCode) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสส่วนราชการนี้ซ้ำกับรหัสหน่วยงาน"); + // } + // if (requestBody.orgChild1ShortName == rootIdExits.orgRootShortName) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้ซ้ำกับอักษรย่อหน่วยงาน"); + // } const order: any = await this.child1Repository.findOne({ where: { @@ -232,23 +232,23 @@ export class OrgChild1Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสส่วนราชการนี้มีอยู่ในระบบแล้ว"); } const chkShort = await this.child1Repository.findOne({ - where: { + where: { id: Not(id), - orgRevisionId: rootIdExits.orgRevisionId, + orgRevisionId: rootIdExits.orgRevisionId, orgRootId: requestBody.orgRootId, - orgChild1ShortName: requestBody.orgChild1ShortName + orgChild1ShortName: requestBody.orgChild1ShortName, }, }); if (chkShort != null) { throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้มีอยู่ในระบบแล้ว"); } - if(requestBody.orgChild1Code == rootIdExits.orgRootCode){ - throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสส่วนราชการนี้ซ้ำกับรหัสหน่วยงาน"); - } - if(requestBody.orgChild1ShortName == rootIdExits.orgRootShortName){ - throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้ซ้ำกับอักษรย่อหน่วยงาน"); - } + // if(requestBody.orgChild1Code == rootIdExits.orgRootCode){ + // throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสส่วนราชการนี้ซ้ำกับรหัสหน่วยงาน"); + // } + // if(requestBody.orgChild1ShortName == rootIdExits.orgRootShortName){ + // throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้ซ้ำกับอักษรย่อหน่วยงาน"); + // } child1.lastUpdateUserId = request.user.sub; child1.lastUpdateFullName = request.user.name; @@ -263,12 +263,12 @@ export class OrgChild1Controller { orgRevisionId: rootIdExits.orgRevisionId, orgRootId: requestBody.orgRootId, orgChild1Id: child1.id, - } + }, }); - if(up_Child2.length > 0){ + if (up_Child2.length > 0) { for (const _child2 of up_Child2) { - _child2.orgChild2ShortName = String(requestBody.orgChild1ShortName) - _child2.orgChild2Code = String(requestBody.orgChild1Code); + _child2.orgChild2ShortName = String(requestBody.orgChild1ShortName); + _child2.orgChild2Code = String(requestBody.orgChild1Code); } await this.child2Repository.save(up_Child2); } @@ -278,12 +278,12 @@ export class OrgChild1Controller { orgRevisionId: rootIdExits.orgRevisionId, orgRootId: requestBody.orgRootId, orgChild1Id: child1.id, - } + }, }); - if(up_Child3.length > 0){ + if (up_Child3.length > 0) { for (const _child3 of up_Child3) { - _child3.orgChild3ShortName = String(requestBody.orgChild1ShortName) - _child3.orgChild3Code = String(requestBody.orgChild1Code); + _child3.orgChild3ShortName = String(requestBody.orgChild1ShortName); + _child3.orgChild3Code = String(requestBody.orgChild1Code); } await this.child3Repository.save(up_Child3); } @@ -293,12 +293,12 @@ export class OrgChild1Controller { orgRevisionId: rootIdExits.orgRevisionId, orgRootId: requestBody.orgRootId, orgChild1Id: child1.id, - } + }, }); - if(up_Child4.length > 0){ + if (up_Child4.length > 0) { for (const _child4 of up_Child4) { - _child4.orgChild4ShortName = String(requestBody.orgChild1ShortName) - _child4.orgChild4Code = String(requestBody.orgChild1Code); + _child4.orgChild4ShortName = String(requestBody.orgChild1ShortName); + _child4.orgChild4Code = String(requestBody.orgChild1Code); } await this.child4Repository.save(up_Child4); } @@ -353,7 +353,7 @@ export class OrgChild1Controller { 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); diff --git a/src/controllers/OrgRootController.ts b/src/controllers/OrgRootController.ts index 6d25cb12..6a682ab6 100644 --- a/src/controllers/OrgRootController.ts +++ b/src/controllers/OrgRootController.ts @@ -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);