From 1845b489ba53bb643281d3e9b6aaa1cba9601491 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 1 Feb 2024 11:34:13 +0700 Subject: [PATCH] no message --- src/controllers/OrganizationController.ts | 95 ++++++++++++----------- 1 file changed, 50 insertions(+), 45 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 7b160685..499783d2 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -865,15 +865,16 @@ export class OrganizationController extends Controller { if (!orgChild1) { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child1"); } - const datas = await this.child1Repository.find({ - where: [ - { isAncestorDNA: orgChild1.isAncestorDNA }, - { isAncestorDNA: Not("00000000-0000-0000-0000-000000000000") }, - { isAncestorDNA: Not(IsNull()) }, - ], - relations: ["orgRevision"], - order: { lastUpdatedAt: "DESC" }, - }); + const datas = await this.child1Repository + .createQueryBuilder("child1") + .where("child1.isAncestorDNA = :isAncestorDNA", { isAncestorDNA: orgChild1.isAncestorDNA }) + .andWhere("child1.isAncestorDNA <> :nullUUID", { + nullUUID: "00000000-0000-0000-0000-000000000000", + }) + .andWhere("child1.isAncestorDNA IS NOT NULL") + .leftJoinAndSelect("child1.orgRevision", "orgRevision") + .orderBy("child1.lastUpdatedAt", "DESC") + .getMany(); const _data = datas.map((item) => ({ id: item.id, orgRevisionName: item.orgRevision == null ? null : item.orgRevision.orgRevisionName, @@ -888,15 +889,16 @@ export class OrganizationController extends Controller { if (!orgChild2) { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child2"); } - const datas = await this.child2Repository.find({ - where: [ - { isAncestorDNA: orgChild2.isAncestorDNA }, - { isAncestorDNA: Not("00000000-0000-0000-0000-000000000000") }, - { isAncestorDNA: Not(IsNull()) }, - ], - relations: ["orgRevision"], - order: { lastUpdatedAt: "DESC" }, - }); + const datas = await this.child2Repository + .createQueryBuilder("child2") + .where("child2.isAncestorDNA = :isAncestorDNA", { isAncestorDNA: orgChild2.isAncestorDNA }) + .andWhere("child2.isAncestorDNA <> :nullUUID", { + nullUUID: "00000000-0000-0000-0000-000000000000", + }) + .andWhere("child2.isAncestorDNA IS NOT NULL") + .leftJoinAndSelect("child2.orgRevision", "orgRevision") + .orderBy("child2.lastUpdatedAt", "DESC") + .getMany(); const _data = datas.map((item) => ({ id: item.id, orgRevisionName: item.orgRevision == null ? null : item.orgRevision.orgRevisionName, @@ -911,15 +913,16 @@ export class OrganizationController extends Controller { if (!orgChild3) { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child3"); } - const datas = await this.child3Repository.find({ - where: [ - { isAncestorDNA: orgChild3.isAncestorDNA }, - { isAncestorDNA: Not("00000000-0000-0000-0000-000000000000") }, - { isAncestorDNA: Not(IsNull()) }, - ], - relations: ["orgRevision"], - order: { lastUpdatedAt: "DESC" }, - }); + const datas = await this.child3Repository + .createQueryBuilder("child3") + .where("child3.isAncestorDNA = :isAncestorDNA", { isAncestorDNA: orgChild3.isAncestorDNA }) + .andWhere("child3.isAncestorDNA <> :nullUUID", { + nullUUID: "00000000-0000-0000-0000-000000000000", + }) + .andWhere("child3.isAncestorDNA IS NOT NULL") + .leftJoinAndSelect("child3.orgRevision", "orgRevision") + .orderBy("child3.lastUpdatedAt", "DESC") + .getMany(); const _data = datas.map((item) => ({ id: item.id, orgRevisionName: item.orgRevision == null ? null : item.orgRevision.orgRevisionName, @@ -934,15 +937,16 @@ export class OrganizationController extends Controller { if (!orgChild4) { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child4"); } - const datas = await this.child4Repository.find({ - where: [ - { isAncestorDNA: orgChild4.isAncestorDNA }, - { isAncestorDNA: Not("00000000-0000-0000-0000-000000000000") }, - { isAncestorDNA: Not(IsNull()) }, - ], - relations: ["orgRevision"], - order: { lastUpdatedAt: "DESC" }, - }); + const datas = await this.child4Repository + .createQueryBuilder("child4") + .where("child4.isAncestorDNA = :isAncestorDNA", { isAncestorDNA: orgChild4.isAncestorDNA }) + .andWhere("child4.isAncestorDNA <> :nullUUID", { + nullUUID: "00000000-0000-0000-0000-000000000000", + }) + .andWhere("child4.isAncestorDNA IS NOT NULL") + .leftJoinAndSelect("child4.orgRevision", "orgRevision") + .orderBy("child4.lastUpdatedAt", "DESC") + .getMany(); const _data = datas.map((item) => ({ id: item.id, orgRevisionName: item.orgRevision == null ? null : item.orgRevision.orgRevisionName, @@ -957,15 +961,16 @@ export class OrganizationController extends Controller { if (!orgRoot) { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Root"); } - const datas = await this.orgRootRepository.find({ - where: [ - { isAncestorDNA: orgRoot.isAncestorDNA }, - { isAncestorDNA: Not("00000000-0000-0000-0000-000000000000") }, - { isAncestorDNA: Not(IsNull()) }, - ], - relations: ["orgRevision"], - order: { lastUpdatedAt: "DESC" }, - }); + const datas = await this.orgRootRepository + .createQueryBuilder("root") + .where("root.isAncestorDNA = :isAncestorDNA", { isAncestorDNA: orgRoot.isAncestorDNA }) + .andWhere("root.isAncestorDNA <> :nullUUID", { + nullUUID: "00000000-0000-0000-0000-000000000000", + }) + .andWhere("root.isAncestorDNA IS NOT NULL") + .leftJoinAndSelect("root.orgRevision", "orgRevision") + .orderBy("root.lastUpdatedAt", "DESC") + .getMany(); const _data = datas.map((item) => ({ id: item.id, orgRevisionName: item.orgRevision == null ? null : item.orgRevision.orgRevisionName,