Skip to content

Commit

Permalink
Merge pull request #157 from credebl/endorser-request-and-submit
Browse files Browse the repository at this point in the history
refactor: organization validation for create and invite for ecosystem
  • Loading branch information
nishad-ayanworks authored Oct 16, 2023
2 parents 71daf64 + c45d887 commit 9004f5d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 10 deletions.
6 changes: 4 additions & 2 deletions apps/api-gateway/src/ecosystem/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -22,7 +24,7 @@ export class EcosystemService extends BaseService {
* @param createEcosystemDto
* @returns Ecosystem creation success
*/
async createEcosystem(createEcosystemDto): Promise<object> {
async createEcosystem(createEcosystemDto: CreateEcosystemDto): Promise<object> {
const payload = { createEcosystemDto };
return this.sendNats(this.serviceProxy, 'create-ecosystem', payload);
}
Expand All @@ -32,7 +34,7 @@ export class EcosystemService extends BaseService {
* @param editEcosystemDto
* @returns Ecosystem creation success
*/
async editEcosystem(editEcosystemDto, ecosystemId): Promise<object> {
async editEcosystem(editEcosystemDto: EditEcosystemDto, ecosystemId:string): Promise<object> {
const payload = { editEcosystemDto, ecosystemId };
return this.sendNats(this.serviceProxy, 'edit-ecosystem', payload);
}
Expand Down
18 changes: 18 additions & 0 deletions apps/ecosystem/interfaces/ecosystem.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
28 changes: 25 additions & 3 deletions apps/ecosystem/src/ecosystem.repository.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<ecosystem> {
Expand Down Expand Up @@ -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<ecosystem_orgs> {
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
Expand Down
16 changes: 12 additions & 4 deletions apps/ecosystem/src/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,10 +37,14 @@ export class EcosystemService {
*/

// eslint-disable-next-line camelcase
async createEcosystem(createEcosystemDto): Promise<object> {
async createEcosystem(createEcosystemDto: CreateEcosystem): Promise<object> {
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;
}
Expand Down Expand Up @@ -180,7 +184,11 @@ export class EcosystemService {
*/
async acceptRejectEcosystemInvitations(acceptRejectInvitation: AcceptRejectEcosystemInvitationDto): Promise<string> {
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);

Expand Down
3 changes: 2 additions & 1 deletion libs/common/src/response-messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
}
}
};

0 comments on commit 9004f5d

Please sign in to comment.