diff --git a/apps/api-gateway/src/ecosystem/ecosystem.service.ts b/apps/api-gateway/src/ecosystem/ecosystem.service.ts index 39e4c10e0..2fdd48a47 100644 --- a/apps/api-gateway/src/ecosystem/ecosystem.service.ts +++ b/apps/api-gateway/src/ecosystem/ecosystem.service.ts @@ -10,6 +10,8 @@ import { GetAllEcosystemMembersDto } from './dtos/get-members.dto'; import { GetAllEndorsementsDto } from './dtos/get-all-endorsements.dto'; import { RequestSchemaDto, RequestCredDefDto } from './dtos/request-schema.dto'; +import { CreateEcosystemDto } from './dtos/create-ecosystem-dto'; +import { EditEcosystemDto } from './dtos/edit-ecosystem-dto'; @Injectable() export class EcosystemService extends BaseService { @@ -22,7 +24,7 @@ export class EcosystemService extends BaseService { * @param createEcosystemDto * @returns Ecosystem creation success */ - async createEcosystem(createEcosystemDto): Promise { + async createEcosystem(createEcosystemDto: CreateEcosystemDto): Promise { const payload = { createEcosystemDto }; return this.sendNats(this.serviceProxy, 'create-ecosystem', payload); } @@ -32,7 +34,7 @@ export class EcosystemService extends BaseService { * @param editEcosystemDto * @returns Ecosystem creation success */ - async editEcosystem(editEcosystemDto, ecosystemId): Promise { + async editEcosystem(editEcosystemDto: EditEcosystemDto, ecosystemId:string): Promise { const payload = { editEcosystemDto, ecosystemId }; return this.sendNats(this.serviceProxy, 'edit-ecosystem', payload); } diff --git a/apps/ecosystem/interfaces/ecosystem.interfaces.ts b/apps/ecosystem/interfaces/ecosystem.interfaces.ts index 0fc061f0a..1e7aa379b 100644 --- a/apps/ecosystem/interfaces/ecosystem.interfaces.ts +++ b/apps/ecosystem/interfaces/ecosystem.interfaces.ts @@ -171,3 +171,21 @@ export interface EndorsementTransactionPayloadDetails { orgId: string; }; } + +export interface CreateEcosystem { + name: string; + + description?: string; + + tags?: string; + + userId: number; + + logo?: string; + + orgName: string; + + orgDid: string; + + orgId?: string; +} \ No newline at end of file diff --git a/apps/ecosystem/src/ecosystem.repository.ts b/apps/ecosystem/src/ecosystem.repository.ts index c7af0371f..7c4e40a2c 100644 --- a/apps/ecosystem/src/ecosystem.repository.ts +++ b/apps/ecosystem/src/ecosystem.repository.ts @@ -1,4 +1,4 @@ -import { Injectable, InternalServerErrorException, Logger } from '@nestjs/common'; +import { BadRequestException, Injectable, InternalServerErrorException, Logger } from '@nestjs/common'; import { PrismaService } from '@credebl/prisma-service'; // eslint-disable-next-line camelcase import { credential_definition, ecosystem, ecosystem_config, ecosystem_invitations, ecosystem_orgs, ecosystem_roles, endorsement_transaction, org_agents, platform_config, schema } from '@prisma/client'; @@ -18,9 +18,9 @@ export class EcosystemRepository { ) { } /** - * Description: Get getAgentEndPoint by orgId + * Description: create ecosystem * @param createEcosystemDto - * @returns Get getAgentEndPoint details + * @returns ecosystem */ // eslint-disable-next-line camelcase async createNewEcosystem(createEcosystemDto): Promise { @@ -150,6 +150,28 @@ export class EcosystemRepository { } } + /** + * + * @param orgId + * @returns Get specific organization details from ecosystem + */ + // eslint-disable-next-line camelcase + async checkEcosystemOrgs(orgId:string): Promise { + try { + if (!orgId) { + throw new BadRequestException(ResponseMessages.ecosystem.error.invalidOrgId); + } + return this.prisma.ecosystem_orgs.findFirst({ + where: { + orgId + } + }); + } catch (error) { + this.logger.error(`error: ${JSON.stringify(error)}`); + throw error; + } + } + /** * * @returns Get ecosystem dashboard card count diff --git a/apps/ecosystem/src/ecosystem.service.ts b/apps/ecosystem/src/ecosystem.service.ts index cf987de63..5b18da802 100644 --- a/apps/ecosystem/src/ecosystem.service.ts +++ b/apps/ecosystem/src/ecosystem.service.ts @@ -13,7 +13,7 @@ import { Invitation, OrgAgentType } from '@credebl/enum/enum'; import { EcosystemOrgStatus, EcosystemRoles, endorsementTransactionStatus, endorsementTransactionType } from '../enums/ecosystem.enum'; import { FetchInvitationsPayload } from '../interfaces/invitations.interface'; import { EcosystemMembersPayload } from '../interfaces/ecosystemMembers.interface'; -import { CredDefMessage, SaveSchema, SchemaMessage, SignedTransactionMessage, saveCredDef, submitTransactionPayload } from '../interfaces/ecosystem.interfaces'; +import { CreateEcosystem, CredDefMessage, SaveSchema, SchemaMessage, SignedTransactionMessage, saveCredDef, submitTransactionPayload } from '../interfaces/ecosystem.interfaces'; import { GetEndorsementsPayload } from '../interfaces/endorsements.interface'; import { CommonConstants } from '@credebl/common/common.constant'; // eslint-disable-next-line camelcase @@ -37,10 +37,14 @@ export class EcosystemService { */ // eslint-disable-next-line camelcase - async createEcosystem(createEcosystemDto): Promise { + async createEcosystem(createEcosystemDto: CreateEcosystem): Promise { + const checkOrganization = await this.ecosystemRepository.checkEcosystemOrgs(createEcosystemDto.orgId); + if (checkOrganization) { + throw new ConflictException(ResponseMessages.ecosystem.error.ecosystemOrgAlready); + }; const createEcosystem = await this.ecosystemRepository.createNewEcosystem(createEcosystemDto); if (!createEcosystem) { - throw new NotFoundException(ResponseMessages.ecosystem.error.update); + throw new NotFoundException(ResponseMessages.ecosystem.error.notCreated); } return createEcosystem; } @@ -180,7 +184,11 @@ export class EcosystemService { */ async acceptRejectEcosystemInvitations(acceptRejectInvitation: AcceptRejectEcosystemInvitationDto): Promise { try { - + const checkOrganization = await this.ecosystemRepository.checkEcosystemOrgs(acceptRejectInvitation.orgId); + + if (checkOrganization) { + throw new ConflictException(ResponseMessages.ecosystem.error.ecosystemOrgAlready); + }; const { orgId, status, invitationId, orgName, orgDid } = acceptRejectInvitation; const invitation = await this.ecosystemRepository.getEcosystemInvitationById(invitationId); diff --git a/libs/common/src/response-messages/index.ts b/libs/common/src/response-messages/index.ts index 679e9590c..52fb01b9d 100644 --- a/libs/common/src/response-messages/index.ts +++ b/libs/common/src/response-messages/index.ts @@ -232,7 +232,8 @@ export const ResponseMessages = { transactionSubmitted: 'Transaction already submitted', invalidAgentUrl: 'Invalid agent url', EndorsementTransactionNotFoundException:'Endorsement transaction with status requested not found', - OrgOrEcosystemNotFoundExceptionForEndorsementTransaction:'Cannot update endorsement transaction status as OrgId and EcosystemId is not present in ecosystemOrg' + OrgOrEcosystemNotFoundExceptionForEndorsementTransaction:'Cannot update endorsement transaction status as OrgId and EcosystemId is not present in ecosystemOrg', + ecosystemOrgAlready: 'Organization is already part of the ecosystem. Please ensure that the organization is not duplicated.' } } }; \ No newline at end of file