diff --git a/src/controllers/OrgChild1Controller.ts b/src/controllers/OrgChild1Controller.ts index a3b72bc7..11ade9e0 100644 --- a/src/controllers/OrgChild1Controller.ts +++ b/src/controllers/OrgChild1Controller.ts @@ -50,7 +50,11 @@ export class OrgChild1Controller { try { const orgChild1 = await this.child1Repository.findOne({ where: { id } }); if (!orgChild1) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 1"); + } + const orgRoot = await this.orgRootRepository.findOne({ where: { id: orgChild1.orgRootId } }); + if (!orgRoot) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root"); } const getOrgChild1 = { "orgChild1Id" : orgChild1.id, @@ -62,7 +66,7 @@ export class OrgChild1Controller { "orgChild1PhoneIn" : orgChild1.orgChild1PhoneIn, "orgChild1Fax" : orgChild1.orgChild1Fax, "orgRevisionId" : orgChild1.orgRevisionId, - "orgCode" : orgChild1.orgChild1Code+"00" + "orgCode" : orgRoot.orgRootCode + orgChild1.orgChild1Code } return new HttpSuccess(getOrgChild1); } catch (error) { diff --git a/src/controllers/OrgChild2Controller.ts b/src/controllers/OrgChild2Controller.ts index 709c1806..446fee98 100644 --- a/src/controllers/OrgChild2Controller.ts +++ b/src/controllers/OrgChild2Controller.ts @@ -20,6 +20,7 @@ import HttpStatusCode from "../interfaces/http-status"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import { OrgRevision } from "../entities/OrgRevision"; +import { OrgRoot } from "../entities/OrgRoot"; import { CreateOrgChild2, OrgChild2, UpdateOrgChild2 } from "../entities/OrgChild2"; import { OrgChild1 } from "../entities/OrgChild1"; import { OrgChild3 } from "../entities/OrgChild3"; @@ -32,6 +33,7 @@ import { OrgChild3 } from "../entities/OrgChild3"; ) @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class OrgChild2Controller extends Controller { + private orgRootRepository = AppDataSource.getRepository(OrgRoot); private child1Repository = AppDataSource.getRepository(OrgChild1); private child2Repository = AppDataSource.getRepository(OrgChild2); private child3Repository = AppDataSource.getRepository(OrgChild3); @@ -49,7 +51,11 @@ export class OrgChild2Controller extends Controller { try { const orgChild2 = await this.child2Repository.findOne({ where: { id } }); if (!orgChild2) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 2"); + } + const orgRoot = await this.orgRootRepository.findOne({ where: { id: orgChild2.orgRootId } }); + if (!orgRoot) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root"); } const getOrgChild2 = { "orgChild2Id" : orgChild2.id, @@ -61,7 +67,7 @@ export class OrgChild2Controller extends Controller { "orgChild2PhoneIn" : orgChild2.orgChild2PhoneIn, "orgChild2Fax" : orgChild2.orgChild2Fax, "orgRevisionId" : orgChild2.orgRevisionId, - "orgCode" : orgChild2.orgChild2Code+"00" + "orgCode" : orgRoot.orgRootCode + orgChild2.orgChild2Code } return new HttpSuccess(getOrgChild2); } catch (error) { diff --git a/src/controllers/OrgChild3Controller.ts b/src/controllers/OrgChild3Controller.ts index 3a929aa3..e9950735 100644 --- a/src/controllers/OrgChild3Controller.ts +++ b/src/controllers/OrgChild3Controller.ts @@ -1,5 +1,6 @@ import { AppDataSource } from "../database/data-source"; import { OrgRevision } from "../entities/OrgRevision"; +import { OrgRoot } from "../entities/OrgRoot"; import { OrgChild2 } from "../entities/OrgChild2"; import { OrgChild3, CreateOrgChild3, UpdateOrgChild3 } from "../entities/OrgChild3"; import { OrgChild4 } from "../entities/OrgChild4"; @@ -30,6 +31,7 @@ import HttpError from "../interfaces/http-error"; ) @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class OrgChild3Controller { + private orgRootRepository = AppDataSource.getRepository(OrgRoot); private child2Repository = AppDataSource.getRepository(OrgChild2); private child3Repository = AppDataSource.getRepository(OrgChild3); private child4Repository = AppDataSource.getRepository(OrgChild4); @@ -47,7 +49,11 @@ export class OrgChild3Controller { try { const orgChild3 = await this.child3Repository.findOne({ where: { id } }); if (!orgChild3) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 3"); + } + const orgRoot = await this.orgRootRepository.findOne({ where: { id: orgChild3.orgRootId } }); + if (!orgRoot) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root"); } const getOrgChild3 = { "orgChild3Id" : orgChild3.id, @@ -59,7 +65,7 @@ export class OrgChild3Controller { "orgChild3PhoneIn" : orgChild3.orgChild3PhoneIn, "orgChild3Fax" : orgChild3.orgChild3Fax, "orgRevisionId" : orgChild3.orgRevisionId, - "orgCode" : orgChild3.orgChild3Code+"00" + "orgCode" : orgRoot.orgRootCode + orgChild3.orgChild3Code } return new HttpSuccess(getOrgChild3); } catch (error) { diff --git a/src/controllers/OrgChild4Controller.ts b/src/controllers/OrgChild4Controller.ts index bcfbc085..d6f3a2e9 100644 --- a/src/controllers/OrgChild4Controller.ts +++ b/src/controllers/OrgChild4Controller.ts @@ -20,6 +20,7 @@ import HttpStatusCode from "../interfaces/http-status"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import { OrgRevision } from "../entities/OrgRevision"; +import { OrgRoot } from "../entities/OrgRoot"; import { CreateOrgChild4, OrgChild4, UpdateOrgChild4 } from "../entities/OrgChild4"; import { OrgChild1 } from "../entities/OrgChild1"; import { OrgChild3 } from "../entities/OrgChild3"; @@ -33,6 +34,7 @@ import { OrgChild3 } from "../entities/OrgChild3"; ) @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class OrgChild4Controller extends Controller { + private orgRootRepository = AppDataSource.getRepository(OrgRoot); private child3Repository = AppDataSource.getRepository(OrgChild3); private child4Repository = AppDataSource.getRepository(OrgChild4); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); @@ -49,8 +51,12 @@ export class OrgChild4Controller extends Controller { try { const orgChild4 = await this.child4Repository.findOne({ where: { id } }); if (!orgChild4) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 4"); } + const orgRoot = await this.orgRootRepository.findOne({ where: { id: orgChild4.orgRootId } }); + if (!orgRoot) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root"); + } const getOrgChild4 = { "orgChild4Id" : orgChild4.id, "orgChild4Name" : orgChild4.orgChild4Name, @@ -61,7 +67,7 @@ export class OrgChild4Controller extends Controller { "orgChild4PhoneIn" : orgChild4.orgChild4PhoneIn, "orgChild4Fax" : orgChild4.orgChild4Fax, "orgRevisionId" : orgChild4.orgRevisionId, - "orgCode" : orgChild4.orgChild4Code+"00" + "orgCode" : orgRoot.orgRootCode + orgChild4.orgChild4Code } return new HttpSuccess(getOrgChild4); } catch (error) { diff --git a/src/controllers/OrgRootController.ts b/src/controllers/OrgRootController.ts index 700ebad2..10b9382d 100644 --- a/src/controllers/OrgRootController.ts +++ b/src/controllers/OrgRootController.ts @@ -41,7 +41,7 @@ export class OrgRootController extends Controller { try { const orgRoot = await this.orgRootRepository.findOne({ where: { id } }); if (!orgRoot) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root"); } const getOrgRoot = { "orgRootId" : orgRoot.id,