validate org_023
This commit is contained in:
parent
8aed1633b2
commit
af7608ec34
1 changed files with 180 additions and 163 deletions
|
|
@ -109,7 +109,7 @@ export class OrganizationController extends Controller {
|
||||||
/**
|
/**
|
||||||
* API สร้างโครงสร้างระดับ4
|
* API สร้างโครงสร้างระดับ4
|
||||||
*
|
*
|
||||||
* @summary ORG_022 - สร้างโครงสร้างใหม่ #23 (ยังไม่เสร็จ)
|
* @summary ORG_022 - สร้างโครงสร้างใหม่ #23
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Post("draft")
|
@Post("draft")
|
||||||
|
|
@ -288,6 +288,12 @@ export class OrganizationController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Get("{id}")
|
@Get("{id}")
|
||||||
async detail(@Path() id: string) {
|
async detail(@Path() id: string) {
|
||||||
|
try {
|
||||||
|
const orgRevision = await this.orgRevisionRepository.findOne({ where: { id } });
|
||||||
|
if (!orgRevision) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
|
||||||
const orgRootData = await AppDataSource.getRepository(OrgRoot)
|
const orgRootData = await AppDataSource.getRepository(OrgRoot)
|
||||||
.createQueryBuilder("orgRoot")
|
.createQueryBuilder("orgRoot")
|
||||||
.where("orgRoot.orgRevisionId = :id", { id })
|
.where("orgRoot.orgRevisionId = :id", { id })
|
||||||
|
|
@ -304,8 +310,9 @@ export class OrganizationController extends Controller {
|
||||||
])
|
])
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
const orgRootIds = orgRootData.map((orgRoot) => orgRoot.id);
|
const orgRootIds = orgRootData.map((orgRoot) => orgRoot.id) || null;
|
||||||
const orgChild1Data = await AppDataSource.getRepository(OrgChild1)
|
const orgChild1Data = orgRootIds && orgRootIds.length > 0
|
||||||
|
? await AppDataSource.getRepository(OrgChild1)
|
||||||
.createQueryBuilder("orgChild1")
|
.createQueryBuilder("orgChild1")
|
||||||
.where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds })
|
.where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds })
|
||||||
.select([
|
.select([
|
||||||
|
|
@ -319,10 +326,12 @@ export class OrganizationController extends Controller {
|
||||||
"orgChild1.orgChild1Fax",
|
"orgChild1.orgChild1Fax",
|
||||||
"orgChild1.orgRootId",
|
"orgChild1.orgRootId",
|
||||||
])
|
])
|
||||||
.getMany();
|
.getMany()
|
||||||
|
:[];
|
||||||
|
|
||||||
const orgChild1Ids = orgChild1Data.map((orgChild1) => orgChild1.id);
|
const orgChild1Ids = orgChild1Data.map((orgChild1) => orgChild1.id) || null;
|
||||||
const orgChild2Data = await AppDataSource.getRepository(OrgChild2)
|
const orgChild2Data = orgChild1Ids && orgChild1Ids.length > 0
|
||||||
|
? await AppDataSource.getRepository(OrgChild2)
|
||||||
.createQueryBuilder("orgChild2")
|
.createQueryBuilder("orgChild2")
|
||||||
.where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids })
|
.where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids })
|
||||||
.select([
|
.select([
|
||||||
|
|
@ -338,10 +347,12 @@ export class OrganizationController extends Controller {
|
||||||
|
|
||||||
"orgChild2.orgChild1Id",
|
"orgChild2.orgChild1Id",
|
||||||
])
|
])
|
||||||
.getMany();
|
.getMany()
|
||||||
|
:[];
|
||||||
|
|
||||||
const orgChild2Ids = orgChild2Data.map((orgChild2) => orgChild2.id);
|
const orgChild2Ids = orgChild2Data.map((orgChild2) => orgChild2.id) || null;
|
||||||
const orgChild3Data = await AppDataSource.getRepository(OrgChild3)
|
const orgChild3Data = orgChild2Ids && orgChild2Ids.length > 0
|
||||||
|
? await AppDataSource.getRepository(OrgChild3)
|
||||||
.createQueryBuilder("orgChild3")
|
.createQueryBuilder("orgChild3")
|
||||||
.where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids })
|
.where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids })
|
||||||
.select([
|
.select([
|
||||||
|
|
@ -357,10 +368,12 @@ export class OrganizationController extends Controller {
|
||||||
|
|
||||||
"orgChild3.orgChild2Id",
|
"orgChild3.orgChild2Id",
|
||||||
])
|
])
|
||||||
.getMany();
|
.getMany()
|
||||||
|
:[];
|
||||||
|
|
||||||
const orgChild3Ids = orgChild3Data.map((orgChild3) => orgChild3.id);
|
const orgChild3Ids = orgChild3Data.map((orgChild3) => orgChild3.id) || null;
|
||||||
const orgChild4Data = await AppDataSource.getRepository(OrgChild4)
|
const orgChild4Data = orgChild3Ids && orgChild3Ids.length > 0
|
||||||
|
? await AppDataSource.getRepository(OrgChild4)
|
||||||
.createQueryBuilder("orgChild4")
|
.createQueryBuilder("orgChild4")
|
||||||
.where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids })
|
.where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids })
|
||||||
.select([
|
.select([
|
||||||
|
|
@ -376,7 +389,8 @@ export class OrganizationController extends Controller {
|
||||||
|
|
||||||
"orgChild4.orgChild3Id",
|
"orgChild4.orgChild3Id",
|
||||||
])
|
])
|
||||||
.getMany();
|
.getMany()
|
||||||
|
:[];
|
||||||
|
|
||||||
const formattedData = orgRootData.map((orgRoot) => {
|
const formattedData = orgRootData.map((orgRoot) => {
|
||||||
return {
|
return {
|
||||||
|
|
@ -459,6 +473,9 @@ export class OrganizationController extends Controller {
|
||||||
});
|
});
|
||||||
|
|
||||||
return new HttpSuccess(formattedData);
|
return new HttpSuccess(formattedData);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue