From 5b5fe5378819216939aa5cdb6b93e1ab631520f4 Mon Sep 17 00:00:00 2001 From: Moulika Kulkarni Date: Tue, 5 Dec 2023 16:20:52 +0530 Subject: [PATCH 1/3] refactor: API-response-refactor Signed-off-by: Moulika Kulkarni --- apps/ecosystem/src/ecosystem.repository.ts | 80 +++++++++++-------- .../repositories/organization.repository.ts | 49 +++++++++--- apps/organization/src/organization.service.ts | 6 +- 3 files changed, 87 insertions(+), 48 deletions(-) diff --git a/apps/ecosystem/src/ecosystem.repository.ts b/apps/ecosystem/src/ecosystem.repository.ts index 9dc1a3665..65533b9ac 100644 --- a/apps/ecosystem/src/ecosystem.repository.ts +++ b/apps/ecosystem/src/ecosystem.repository.ts @@ -113,7 +113,18 @@ export class EcosystemRepository { * @returns Get all ecosystem details */ // eslint-disable-next-line camelcase - async getAllEcosystemDetails(orgId: string): Promise { + async getAllEcosystemDetails(orgId: string): Promise<{ + ecosystemOrgs: { + ecosystemRole: { + id: string; + name: string; + description: string; + createDateTime: Date; + lastChangedDateTime: Date; + deletedAt: Date; + }; + }[]; + }[]> { try { const ecosystemDetails = await this.prisma.ecosystem.findMany({ where: { @@ -123,12 +134,17 @@ export class EcosystemRepository { } } }, - include: { + select: { + id: true, + name: true, + description: true, + logoUrl: true, + autoEndorsement: true, ecosystemOrgs: { where: { orgId }, - include: { + select: { ecosystemRole: true } } @@ -188,7 +204,7 @@ export class EcosystemRepository { where: { orgId }, - include:{ + include: { ecosystemRole: true } }); @@ -230,21 +246,21 @@ export class EcosystemRepository { } } - // eslint-disable-next-line camelcase - async getSpecificEcosystemConfig(key: string): Promise { - try { - return await this.prisma.ecosystem_config.findFirst( - { - where: { - key - } + // eslint-disable-next-line camelcase + async getSpecificEcosystemConfig(key: string): Promise { + try { + return await this.prisma.ecosystem_config.findFirst( + { + where: { + key } - ); - } catch (error) { - this.logger.error(`error: ${JSON.stringify(error)}`); - throw error; - } + } + ); + } catch (error) { + this.logger.error(`error: ${JSON.stringify(error)}`); + throw error; } + } async getEcosystemMembersCount(ecosystemId: string): Promise { try { @@ -398,7 +414,7 @@ export class EcosystemRepository { // eslint-disable-next-line camelcase ): Promise { try { - + return this.prisma.ecosystem_invitations.create({ data: { email, @@ -466,7 +482,7 @@ export class EcosystemRepository { ecosystem: true, ecosystemRole: true, organisation: { - select:{ + select: { name: true, orgSlug: true, // eslint-disable-next-line camelcase @@ -577,9 +593,9 @@ export class EcosystemRepository { status: true, type: true, ecosystemOrgs: { - include:{ + include: { organisation: { - select:{ + select: { name: true, orgSlug: true } @@ -672,7 +688,7 @@ export class EcosystemRepository { } }); const schemasCount = schemaArray.length; - + this.logger.error(`In error schemaDetails3: ${JSON.stringify(schemasResult)}`); return { schemasCount, schemasResult }; @@ -695,7 +711,7 @@ export class EcosystemRepository { } const agentDetails = await this.prisma.org_agents.findFirst({ where: { - orgId:orgId.toString() + orgId: orgId.toString() } }); return agentDetails; @@ -1079,16 +1095,16 @@ export class EcosystemRepository { async getOrgAgentType(orgAgentId: string): Promise { try { - const { agent } = await this.prisma.org_agents_type.findFirst({ - where: { - id: orgAgentId - } - }); + const { agent } = await this.prisma.org_agents_type.findFirst({ + where: { + id: orgAgentId + } + }); - return agent; + return agent; } catch (error) { - this.logger.error(`[getOrgAgentType] - error: ${JSON.stringify(error)}`); - throw error; + this.logger.error(`[getOrgAgentType] - error: ${JSON.stringify(error)}`); + throw error; } -} + } } diff --git a/apps/organization/repositories/organization.repository.ts b/apps/organization/repositories/organization.repository.ts index 4249acc55..a56b2ec65 100644 --- a/apps/organization/repositories/organization.repository.ts +++ b/apps/organization/repositories/organization.repository.ts @@ -261,26 +261,49 @@ export class OrganizationRepository { } } - async getOrganization(queryObject: object): Promise { + async getOrganization(queryObject: object): Promise { try { return this.prisma.organisation.findFirst({ where: { ...queryObject }, - include: { - schema: true, - org_agents: { - include: { - agents_type: true, - agent_invitations: true, - org_agent_type: true, - ledgers: true + select: { + id: true, + name: true, + description: true, + orgSlug: true, + logoUrl: true, + website: true, + publicProfile: true, + schema: { + select: { + id: true, + name: true } }, - userOrgRoles: { - include: { - user: true, - orgRole: true + org_agents: { + select: { + orgDid: true, + id: true, + walletName: true, + agentSpinUpStatus: true, + agentsTypeId: true, + agent_invitations: { + select: { + id: true, + connectionInvitation: true, + multiUse: true, + createDateTime: true, + lastChangedDateTime:true + } + }, + ledgers: { + select: { + id: true, + name: true, + networkType: true + } + } } } } diff --git a/apps/organization/src/organization.service.ts b/apps/organization/src/organization.service.ts index 37ab5fc68..d5755864e 100644 --- a/apps/organization/src/organization.service.ts +++ b/apps/organization/src/organization.service.ts @@ -181,10 +181,10 @@ export class OrganizationService { } } - async getPublicProfile(payload: { orgSlug: string }): Promise { + async getPublicProfile(payload: { orgSlug: string }): Promise { const { orgSlug } = payload; try { - + const query = { orgSlug, publicProfile: true @@ -195,7 +195,7 @@ export class OrganizationService { throw new NotFoundException(ResponseMessages.organisation.error.profileNotFound); } - const credentials = await this.organizationRepository.getCredDefByOrg(organizationDetails.id); + const credentials = await this.organizationRepository.getCredDefByOrg(organizationDetails['id']); organizationDetails['credential_definitions'] = credentials; return organizationDetails; From 98c602886aff8a2aab0550f701885a905ee5490f Mon Sep 17 00:00:00 2001 From: Moulika Kulkarni Date: Tue, 5 Dec 2023 17:15:57 +0530 Subject: [PATCH 2/3] refactor: API-response-refactor Signed-off-by: Moulika Kulkarni --- apps/organization/repositories/organization.repository.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/organization/repositories/organization.repository.ts b/apps/organization/repositories/organization.repository.ts index a56b2ec65..5e56ceb56 100644 --- a/apps/organization/repositories/organization.repository.ts +++ b/apps/organization/repositories/organization.repository.ts @@ -288,6 +288,8 @@ export class OrganizationRepository { walletName: true, agentSpinUpStatus: true, agentsTypeId: true, + createDateTime: true, + orgAgentTypeId:true, agent_invitations: { select: { id: true, @@ -297,6 +299,7 @@ export class OrganizationRepository { lastChangedDateTime:true } }, + org_agent_type: true, ledgers: { select: { id: true, From 091e054915ce3ce90afbc6f555dd31faa50d7d5d Mon Sep 17 00:00:00 2001 From: Moulika Kulkarni Date: Tue, 5 Dec 2023 18:36:16 +0530 Subject: [PATCH 3/3] refactor: API-response-refactor Signed-off-by: Moulika Kulkarni --- apps/ecosystem/interfaces/ecosystem.interfaces.ts | 13 +++++++++++++ apps/ecosystem/src/ecosystem.repository.ts | 15 ++------------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/apps/ecosystem/interfaces/ecosystem.interfaces.ts b/apps/ecosystem/interfaces/ecosystem.interfaces.ts index bb3e8b94f..e37bee334 100644 --- a/apps/ecosystem/interfaces/ecosystem.interfaces.ts +++ b/apps/ecosystem/interfaces/ecosystem.interfaces.ts @@ -225,4 +225,17 @@ export interface OrgAgent { orgId: string; orgAgentTypeId: string; ledgerId: string; +} + +export interface EcosystemDetails { + ecosystemOrgs: { + ecosystemRole: { + id: string; + name: string; + description: string; + createDateTime: Date; + lastChangedDateTime: Date; + deletedAt: Date; + }; + }[]; } \ No newline at end of file diff --git a/apps/ecosystem/src/ecosystem.repository.ts b/apps/ecosystem/src/ecosystem.repository.ts index 65533b9ac..a8be10f59 100644 --- a/apps/ecosystem/src/ecosystem.repository.ts +++ b/apps/ecosystem/src/ecosystem.repository.ts @@ -4,7 +4,7 @@ import { PrismaService } from '@credebl/prisma-service'; import { credential_definition, ecosystem, ecosystem_config, ecosystem_invitations, ecosystem_orgs, ecosystem_roles, endorsement_transaction, org_agents, platform_config, schema } from '@prisma/client'; import { DeploymentModeType, EcosystemInvitationStatus, EcosystemOrgStatus, EcosystemRoles, endorsementTransactionStatus, endorsementTransactionType } from '../enums/ecosystem.enum'; import { updateEcosystemOrgsDto } from '../dtos/update-ecosystemOrgs.dto'; -import { SaveSchema, SchemaTransactionResponse, saveCredDef } from '../interfaces/ecosystem.interfaces'; +import { EcosystemDetails, SaveSchema, SchemaTransactionResponse, saveCredDef } from '../interfaces/ecosystem.interfaces'; import { ResponseMessages } from '@credebl/common/response-messages'; import { NotFoundException } from '@nestjs/common'; import { CommonConstants } from '@credebl/common/common.constant'; @@ -113,18 +113,7 @@ export class EcosystemRepository { * @returns Get all ecosystem details */ // eslint-disable-next-line camelcase - async getAllEcosystemDetails(orgId: string): Promise<{ - ecosystemOrgs: { - ecosystemRole: { - id: string; - name: string; - description: string; - createDateTime: Date; - lastChangedDateTime: Date; - deletedAt: Date; - }; - }[]; - }[]> { + async getAllEcosystemDetails(orgId: string): Promise { try { const ecosystemDetails = await this.prisma.ecosystem.findMany({ where: {