Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor:Api response #331

Merged
merged 4 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions apps/ecosystem/interfaces/ecosystem.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}[];
}
71 changes: 38 additions & 33 deletions apps/ecosystem/src/ecosystem.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -113,7 +113,7 @@ export class EcosystemRepository {
* @returns Get all ecosystem details
*/
// eslint-disable-next-line camelcase
async getAllEcosystemDetails(orgId: string): Promise<ecosystem[]> {
async getAllEcosystemDetails(orgId: string): Promise<EcosystemDetails[]> {
try {
const ecosystemDetails = await this.prisma.ecosystem.findMany({
where: {
Expand All @@ -123,12 +123,17 @@ export class EcosystemRepository {
}
}
},
include: {
select: {
id: true,
name: true,
description: true,
logoUrl: true,
autoEndorsement: true,
ecosystemOrgs: {
where: {
orgId
},
include: {
select: {
ecosystemRole: true
}
}
Expand Down Expand Up @@ -188,7 +193,7 @@ export class EcosystemRepository {
where: {
orgId
},
include:{
include: {
ecosystemRole: true
}
});
Expand Down Expand Up @@ -230,21 +235,21 @@ export class EcosystemRepository {
}
}

// eslint-disable-next-line camelcase
async getSpecificEcosystemConfig(key: string): Promise<ecosystem_config> {
try {
return await this.prisma.ecosystem_config.findFirst(
{
where: {
key
}
// eslint-disable-next-line camelcase
async getSpecificEcosystemConfig(key: string): Promise<ecosystem_config> {
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<number> {
try {
Expand Down Expand Up @@ -398,7 +403,7 @@ export class EcosystemRepository {
// eslint-disable-next-line camelcase
): Promise<ecosystem_invitations> {
try {

return this.prisma.ecosystem_invitations.create({
data: {
email,
Expand Down Expand Up @@ -466,7 +471,7 @@ export class EcosystemRepository {
ecosystem: true,
ecosystemRole: true,
organisation: {
select:{
select: {
name: true,
orgSlug: true,
// eslint-disable-next-line camelcase
Expand Down Expand Up @@ -577,9 +582,9 @@ export class EcosystemRepository {
status: true,
type: true,
ecosystemOrgs: {
include:{
include: {
organisation: {
select:{
select: {
name: true,
orgSlug: true
}
Expand Down Expand Up @@ -672,7 +677,7 @@ export class EcosystemRepository {
}
});
const schemasCount = schemaArray.length;

this.logger.error(`In error schemaDetails3: ${JSON.stringify(schemasResult)}`);
return { schemasCount, schemasResult };

Expand All @@ -695,7 +700,7 @@ export class EcosystemRepository {
}
const agentDetails = await this.prisma.org_agents.findFirst({
where: {
orgId:orgId.toString()
orgId: orgId.toString()
}
});
return agentDetails;
Expand Down Expand Up @@ -1079,16 +1084,16 @@ export class EcosystemRepository {
async getOrgAgentType(orgAgentId: string): Promise<string> {
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;
}
}
}
}
52 changes: 39 additions & 13 deletions apps/organization/repositories/organization.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,26 +261,52 @@ export class OrganizationRepository {
}
}

async getOrganization(queryObject: object): Promise<organisation> {
async getOrganization(queryObject: object): Promise<object> {
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,
createDateTime: true,
orgAgentTypeId:true,
agent_invitations: {
select: {
id: true,
connectionInvitation: true,
multiUse: true,
createDateTime: true,
lastChangedDateTime:true
}
},
org_agent_type: true,
ledgers: {
select: {
id: true,
name: true,
networkType: true
}
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions apps/organization/src/organization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ export class OrganizationService {
}
}

async getPublicProfile(payload: { orgSlug: string }): Promise<organisation> {
async getPublicProfile(payload: { orgSlug: string }): Promise<object> {
const { orgSlug } = payload;
try {

const query = {
orgSlug,
publicProfile: true
Expand All @@ -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;

Expand Down