diff --git a/apps/api-gateway/src/dtos/create-schema.dto.ts b/apps/api-gateway/src/dtos/create-schema.dto.ts index 4705dfe77..bac862dfb 100644 --- a/apps/api-gateway/src/dtos/create-schema.dto.ts +++ b/apps/api-gateway/src/dtos/create-schema.dto.ts @@ -6,32 +6,31 @@ import { IsNotSQLInjection, trim } from '@credebl/common/cast.helper'; import { JSONSchemaType, SchemaTypeEnum, W3CSchemaDataType } from '@credebl/enum/enum'; class W3CAttributeValue { - @ApiProperty() @IsString() @Transform(({ value }) => trim(value)) @IsNotEmpty({ message: 'attributeName is required' }) attributeName: string; - @ApiProperty({ - description: 'The type of the schema', - enum: W3CSchemaDataType, - example: W3CSchemaDataType.STRING - }) - @IsEnum(W3CSchemaDataType, { message: 'Schema data type must be a valid type' }) - schemaDataType: W3CSchemaDataType; - @ApiProperty() @IsString() @Transform(({ value }) => trim(value)) @IsNotEmpty({ message: 'displayName is required' }) displayName: string; + @ApiProperty({ + description: 'The type of the schema', + enum: W3CSchemaDataType, + example: W3CSchemaDataType.STRING + }) + @IsEnum(W3CSchemaDataType, { message: 'Schema data type must be a valid type' }) + schemaDataType: W3CSchemaDataType; + @ApiProperty() @IsBoolean() @IsNotEmpty({ message: 'isRequired property is required' }) isRequired: boolean; -} + } class AttributeValue { @ApiProperty() diff --git a/apps/api-gateway/src/ecosystem/dtos/request-schema.dto.ts b/apps/api-gateway/src/ecosystem/dtos/request-schema.dto.ts index e8d9b97c3..03dbd03b5 100644 --- a/apps/api-gateway/src/ecosystem/dtos/request-schema.dto.ts +++ b/apps/api-gateway/src/ecosystem/dtos/request-schema.dto.ts @@ -1,7 +1,8 @@ -import { ApiProperty } from '@nestjs/swagger'; +import { ApiExtraModels, ApiProperty, getSchemaPath } from '@nestjs/swagger'; import { Transform, Type } from 'class-transformer'; -import { ArrayMinSize, IsArray, IsBoolean, IsNotEmpty, IsOptional, IsString, ValidateNested } from 'class-validator'; +import { ArrayMinSize, IsArray, IsBoolean, IsEnum, IsNotEmpty, IsOptional, IsString, ValidateNested } from 'class-validator'; import { trim } from '@credebl/common/cast.helper'; +import { JSONSchemaType, SchemaTypeEnum, W3CSchemaDataType } from '@credebl/enum/enum'; class AttributeValues { @@ -31,20 +32,19 @@ class AttributeValues { } - -export class RequestSchemaDto { +export class RequestIndySchemaDto { @ApiProperty() @Transform(({ value }) => trim(value)) @IsNotEmpty({ message: 'Schema name is required' }) @IsString({ message: 'name must be in string format.' }) - name: string; + schemaName: string; @ApiProperty() @Transform(({ value }) => trim(value)) @IsNotEmpty({ message: 'Schema version is required' }) @IsString({ message: 'version must be in string format.' }) - version: string; + schemaVersion: string; @ApiProperty({ type: [AttributeValues], @@ -63,92 +63,123 @@ export class RequestSchemaDto { @ValidateNested({ each: true }) @Type(() => AttributeValues) attributes: AttributeValues[]; - - @ApiProperty() - @IsBoolean({ message: 'endorse must be a boolean.' }) - @IsOptional() - endorse?: boolean; - - userId?: string; - } class W3CSchemaAttributesValue { @ApiProperty() + @IsString() @Transform(({ value }) => trim(value)) - @IsNotEmpty({ message: 'title is required' }) - @IsString({ message: 'title must be in string format' }) - title: string; + @IsNotEmpty({ message: 'attributeName is required' }) + attributeName: string; + + @ApiProperty({ + description: 'The type of the schema', + enum: W3CSchemaDataType, + example: W3CSchemaDataType.STRING + }) + @IsEnum(W3CSchemaDataType, { message: 'Schema data type must be a valid type' }) + schemaDataType: W3CSchemaDataType; @ApiProperty() + @IsString() @Transform(({ value }) => trim(value)) - @IsNotEmpty({ message: 'type is required' }) - @IsString({ message: 'type must be in string format' }) - type: string; + @IsNotEmpty({ message: 'displayName is required' }) + displayName: string; @ApiProperty() - @IsBoolean({ message: 'isRequired property must be in boolean format' }) + @IsBoolean() @IsNotEmpty({ message: 'isRequired property is required' }) isRequired: boolean; } -export class RequestW3CSchemaDto { +export class SchemaDetails { + @ApiProperty() + @IsString({ message: 'name must be a string.' }) + name: string; @ApiProperty() - @Transform(({ value }) => trim(value)) - @IsNotEmpty({ message: 'schemaName is required' }) - @IsString({ message: 'schemaName must be in string format.' }) - schemaName: string; + @IsString({ message: 'version must be a string.' }) + version: string; @ApiProperty({ - type: [W3CSchemaAttributesValue], - 'example': [ - { - title: 'name', - type: 'string', - isRequired: true - } - ] + example: ['name', 'id'] }) - @IsArray({ message: 'schemaAttributes must be an array' }) - @IsNotEmpty({ message: 'schemaAttributes are required' }) - @ArrayMinSize(1) - @ValidateNested({ each: true }) - @Type(() => W3CSchemaAttributesValue) - schemaAttributes: W3CSchemaAttributesValue[]; + @IsArray({ message: 'attributes must be an array.' }) + @IsNotEmpty({ message: 'please provide valid attributes.' }) + attributes: string[]; + +} + +export class RequestW3CSchemaDto { @ApiProperty() - @Transform(({ value }) => trim(value)) - @IsNotEmpty({ message: 'did is required' }) - @IsString({ message: 'did must be in string format.' }) - did: string; + @IsString({ message: 'schemaName must be a string' }) + @Transform(({ value }) => value.trim()) + @IsNotEmpty({ message: 'schemaName is required' }) + schemaName: string; @ApiProperty() - @Transform(({ value }) => trim(value)) + @IsString({ message: 'description must be a string' }) @IsNotEmpty({ message: 'description is required' }) - @IsString({ message: 'description must be in string format.' }) description: string; - userId?: string; + @ApiProperty({ + type: [W3CSchemaAttributesValue], + 'example': [ + { + attributeName: 'name', + schemaDataType: 'string', + displayName: 'Name', + isRequired: true + } + ] + }) + @ValidateNested({each: true}) + @Type(() => W3CSchemaAttributesValue) + @IsNotEmpty() + attributes: W3CSchemaAttributesValue []; + @ApiProperty({ + description: 'The type of the schema', + enum: JSONSchemaType, + example: JSONSchemaType.POLYGON_W3C + }) + @IsEnum(JSONSchemaType, { message: 'Schema type must be a valid schema type' }) + @IsNotEmpty({ message: 'Type is required' }) + schemaType: JSONSchemaType; } -export class SchemaDetails { - @ApiProperty() - @IsString({ message: 'name must be a string.' }) - name: string; + +@ApiExtraModels(RequestIndySchemaDto, RequestW3CSchemaDto) +export class RequestSchemaDto { @ApiProperty() - @IsString({ message: 'version must be a string.' }) - version: string; + @IsBoolean({ message: 'endorse property must be a boolean.' }) + @IsNotEmpty({ message: 'endorse property is required' }) + endorse?: boolean; @ApiProperty({ - example: ['name', 'id'] + description: 'The type of the schema', + enum: SchemaTypeEnum, + example: SchemaTypeEnum.INDY }) - @IsArray({ message: 'attributes must be an array.' }) - @IsNotEmpty({ message: 'please provide valid attributes.' }) - attributes: string[]; - + @IsEnum(SchemaTypeEnum, { message: 'Type must be a valid schema type' }) + @IsNotEmpty({ message: 'Type is required' }) + type: SchemaTypeEnum; + + @ApiProperty({ + type: Object, + oneOf: [{ $ref: getSchemaPath(RequestIndySchemaDto) }, { $ref: getSchemaPath(RequestW3CSchemaDto) }] + }) + @ValidateNested() + @Type(({ object }) => { + if (object.type === SchemaTypeEnum.INDY) { + return RequestIndySchemaDto; + } else if (object.type === SchemaTypeEnum.JSON) { + return RequestW3CSchemaDto; + } + }) + schemaPayload: RequestIndySchemaDto | RequestW3CSchemaDto; } export class RequestCredDefDto { diff --git a/apps/api-gateway/src/ecosystem/ecosystem.controller.ts b/apps/api-gateway/src/ecosystem/ecosystem.controller.ts index cf2caac02..5c2118605 100644 --- a/apps/api-gateway/src/ecosystem/ecosystem.controller.ts +++ b/apps/api-gateway/src/ecosystem/ecosystem.controller.ts @@ -1,4 +1,4 @@ -import { ApiBearerAuth, ApiBody, ApiExcludeEndpoint, ApiExtraModels, ApiForbiddenResponse, ApiOperation, ApiQuery, ApiResponse, ApiTags, ApiUnauthorizedResponse, getSchemaPath } from '@nestjs/swagger'; +import { ApiBearerAuth, ApiExcludeEndpoint, ApiExtraModels, ApiForbiddenResponse, ApiOperation, ApiQuery, ApiResponse, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger'; import { EcosystemService } from './ecosystem.service'; import { Controller, UseFilters, Put, Post, Get, Body, Param, UseGuards, Query, BadRequestException, Delete, HttpStatus, Res, ParseUUIDPipe } from '@nestjs/common'; import { RequestCredDefDto, RequestSchemaDto, RequestW3CSchemaDto } from './dtos/request-schema.dto'; @@ -12,7 +12,7 @@ import { CustomExceptionFilter } from 'apps/api-gateway/common/exception-handler import { EditEcosystemDto } from './dtos/edit-ecosystem-dto'; import { AuthGuard } from '@nestjs/passport'; import { GetAllSentEcosystemInvitationsDto } from './dtos/get-all-received-invitations.dto'; -import { EcosystemRoles, Invitation, schemaRequestType } from '@credebl/enum/enum'; +import { EcosystemRoles, Invitation } from '@credebl/enum/enum'; import { User } from '../authz/decorators/user.decorator'; import { BulkEcosystemInvitationDto } from './dtos/send-invitation.dto'; // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -28,7 +28,7 @@ import { CreateEcosystemDto } from './dtos/create-ecosystem-dto'; import { PaginationDto } from '@credebl/common/dtos/pagination.dto'; import { IEcosystemInvitations, IEditEcosystem, IEndorsementTransaction } from 'apps/ecosystem/interfaces/ecosystem.interfaces'; import { AddOrganizationsDto } from './dtos/add-organizations.dto'; -import { TrimStringParamPipe, validateSchemaPayload } from '@credebl/common/cast.helper'; +import { TrimStringParamPipe } from '@credebl/common/cast.helper'; @UseFilters(CustomExceptionFilter) @@ -312,24 +312,12 @@ export class EcosystemController { @ApiExtraModels(RequestSchemaDto, RequestW3CSchemaDto) @ApiOperation({ summary: 'Request new schema', description: 'Create request for new schema' }) @ApiResponse({ status: HttpStatus.CREATED, description: 'Created', type: ApiResponseDto }) - @ApiQuery({ - name: 'schemaType', - enum: schemaRequestType - }) - @ApiBody({ - schema: { - oneOf: [ - { $ref: getSchemaPath(RequestSchemaDto), description: 'Indy based schema' }, - { $ref: getSchemaPath(RequestW3CSchemaDto), description: 'W3C based schema' } - ] - } - }) @UseGuards(AuthGuard('jwt'), EcosystemRolesGuard, OrgRolesGuard) @ApiBearerAuth() @EcosystemsRoles(EcosystemRoles.ECOSYSTEM_MEMBER, EcosystemRoles.ECOSYSTEM_LEAD, EcosystemRoles.ECOSYSTEM_OWNER) @Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.ISSUER) async requestSchemaTransaction( - @Body() requestSchemaPayload: RequestSchemaDto | RequestW3CSchemaDto, + @Body() requestSchemaPayload: RequestSchemaDto, @Param( 'orgId', new ParseUUIDPipe({ @@ -340,19 +328,14 @@ export class EcosystemController { ) orgId: string, @Param('ecosystemId', TrimStringParamPipe) ecosystemId: string, @Res() res: Response, - @User() user: user, - @Query('schemaType') schemaType: schemaRequestType = schemaRequestType.INDY + @User() user: user ): Promise { - requestSchemaPayload.userId = user.id; - - - validateSchemaPayload(requestSchemaPayload, schemaType); const createSchemaRequest = await this.ecosystemService.schemaEndorsementRequest( requestSchemaPayload, + user, orgId, - ecosystemId, - schemaType + ecosystemId ); const finalResponse: IResponse = { @@ -400,7 +383,7 @@ export class EcosystemController { @ApiBearerAuth() @EcosystemsRoles(EcosystemRoles.ECOSYSTEM_MEMBER) @Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.ISSUER) - async requestCredDefTransaction(@Body() requestCredDefPayload: RequestCredDefDto, @Param('orgId', new ParseUUIDPipe({exceptionFactory: (): Error => { throw new BadRequestException(ResponseMessages.organisation.error.invalidOrgId); }})) orgId: string, @Param('ecosystemId', TrimStringParamPipe) ecosystemId: string, @Res() res: Response, @User() user: user): Promise { + async requestCredDefTransaction(@Body() requestCredDefPayload: RequestCredDefDto, @Param('ecosystemId', TrimStringParamPipe) ecosystemId: string, @Param('orgId', new ParseUUIDPipe({exceptionFactory: (): Error => { throw new BadRequestException(ResponseMessages.organisation.error.invalidOrgId); }})) orgId: string, @Res() res: Response, @User() user: user): Promise { requestCredDefPayload.userId = user.id; const createCredDefRequest: IEndorsementTransaction = await this.ecosystemService.credDefEndorsementRequest(requestCredDefPayload, orgId, ecosystemId); const finalResponse: IResponse = { @@ -466,9 +449,10 @@ export class EcosystemController { }) ) orgId: string, + @User() user: user, @Res() res: Response ): Promise { - const transactionResponse = await this.ecosystemService.submitTransaction(endorsementId, ecosystemId, orgId); + const transactionResponse = await this.ecosystemService.submitTransaction(endorsementId, ecosystemId, orgId, user); const finalResponse: IResponse = { statusCode: HttpStatus.CREATED, message: ResponseMessages.ecosystem.success.submit, diff --git a/apps/api-gateway/src/ecosystem/ecosystem.service.ts b/apps/api-gateway/src/ecosystem/ecosystem.service.ts index dc1fb0c7a..3e14a6758 100644 --- a/apps/api-gateway/src/ecosystem/ecosystem.service.ts +++ b/apps/api-gateway/src/ecosystem/ecosystem.service.ts @@ -7,14 +7,13 @@ import { GetAllSentEcosystemInvitationsDto } from './dtos/get-all-received-invit import { GetAllEcosystemMembersDto } from './dtos/get-members.dto'; import { GetAllEndorsementsDto } from './dtos/get-all-endorsements.dto'; -import { RequestSchemaDto, RequestCredDefDto, RequestW3CSchemaDto } from './dtos/request-schema.dto'; +import { RequestSchemaDto, RequestCredDefDto} from './dtos/request-schema.dto'; import { CreateEcosystemDto } from './dtos/create-ecosystem-dto'; import { EditEcosystemDto } from './dtos/edit-ecosystem-dto'; import { IEcosystemDashboard, IEcosystemInvitation, IEcosystemInvitations, IEcosystem, IEditEcosystem, IEndorsementTransaction, ISchemaResponse } from 'apps/ecosystem/interfaces/ecosystem.interfaces'; import { PaginationDto } from '@credebl/common/dtos/pagination.dto'; import { IEcosystemDataDeletionResults, IEcosystemDetails } from '@credebl/common/interfaces/ecosystem.interface'; import { AddOrganizationsDto } from './dtos/add-organizations.dto'; -import { schemaRequestType } from '@credebl/enum/enum'; import { user } from '@prisma/client'; @Injectable() @@ -165,12 +164,12 @@ export class EcosystemService extends BaseService { } async schemaEndorsementRequest( - requestSchemaPayload: RequestSchemaDto | RequestW3CSchemaDto, + requestSchemaPayload: RequestSchemaDto, + user: user, orgId: string, - ecosystemId: string, - schemaType: schemaRequestType = schemaRequestType.INDY + ecosystemId: string ): Promise { - const payload = { requestSchemaPayload, schemaType, orgId, ecosystemId }; + const payload = { requestSchemaPayload, user, orgId, ecosystemId }; return this.sendNatsMessage(this.serviceProxy, 'schema-endorsement-request', payload); } @@ -188,8 +187,8 @@ export class EcosystemService extends BaseService { return this.sendNatsMessage(this.serviceProxy, 'sign-endorsement-transaction', payload); } - async submitTransaction(endorsementId: string, ecosystemId: string, orgId: string): Promise { - const payload = { endorsementId, ecosystemId, orgId }; + async submitTransaction(endorsementId: string, ecosystemId: string, orgId: string, user: user): Promise { + const payload = { endorsementId, ecosystemId, orgId, user }; return this.sendNatsMessage(this.serviceProxy, 'submit-endorsement-transaction', payload); } diff --git a/apps/ecosystem/interfaces/ecosystem.interfaces.ts b/apps/ecosystem/interfaces/ecosystem.interfaces.ts index 8d18a8c5c..4b23303a9 100644 --- a/apps/ecosystem/interfaces/ecosystem.interfaces.ts +++ b/apps/ecosystem/interfaces/ecosystem.interfaces.ts @@ -1,4 +1,6 @@ +import { JSONSchemaType, SchemaTypeEnum, W3CSchemaDataType } from '@credebl/enum/enum'; import { Prisma } from '@prisma/client'; +import { IUserRequestInterface } from 'apps/ledger/src/schema/interfaces/schema.interface'; export interface AttributeValue { attributeName: string; schemaDataType: string; @@ -6,25 +8,26 @@ export interface AttributeValue { } export interface IW3CSchemaAttributesValue { - title: string; - type: string; + attributeName: string; + schemaDataType: W3CSchemaDataType; + displayName: string; + isRequired: boolean; } - export interface IRequestSchemaEndorsement { - orgId: string; - userId?: string; - name: string; - version: string; - attributes: AttributeValue[]; - endorse?: boolean; + type: SchemaTypeEnum, + endorse?: boolean, + schemaPayload: IRequestIndySchemaEndorsement | IRequestW3CSchemaEndorsement } +export interface IRequestIndySchemaEndorsement { + schemaName: string; + schemaVersion: string; + attributes: AttributeValue[]; +} export interface IRequestW3CSchemaEndorsement { - orgId: string; - userId?: string; schemaName: string; - did: string; - schemaAttributes: IW3CSchemaAttributesValue[]; + attributes: IW3CSchemaAttributesValue[]; + schemaType: JSONSchemaType; description: string; } @@ -276,6 +279,7 @@ export interface ITransactionData { ecosystemId: string; ecosystemLeadAgentEndPoint?: string; orgId?: string; + user?: IUserRequestInterface } export interface IEcosystemDashboard { @@ -450,3 +454,34 @@ export interface IEcosystemData { ledgers: Prisma.JsonValue; ecosystemOrgs: IEcosystemMemberOrgs[]; } + +interface IW3CAttributeValue { + attributeName: string; + schemaDataType: W3CSchemaDataType; + displayName: string; + isRequired: boolean; +} + +export interface ISubmitIndySchema { + schemaVersion?: string; + schemaName: string; + attributes: IAttributeValue[]; + orgId?: string; + orgDid?: string; +} +export interface ISubmitW3CSchema { + attributes: IW3CAttributeValue[]; + schemaName: string; + description: string; + schemaType: JSONSchemaType; +} +export interface ISubmitSchemaEndorsement { + type: SchemaTypeEnum; + schemaPayload: ISubmitIndySchema | ISubmitW3CSchema; +} + +export interface IschemaPayload { + schemaDetails: ISubmitSchemaEndorsement, + user: IUserRequestInterface, + orgId: string +} diff --git a/apps/ecosystem/src/ecosystem.controller.ts b/apps/ecosystem/src/ecosystem.controller.ts index d9d60b7ab..f0032497b 100644 --- a/apps/ecosystem/src/ecosystem.controller.ts +++ b/apps/ecosystem/src/ecosystem.controller.ts @@ -1,17 +1,15 @@ -import { Controller, Logger } from '@nestjs/common'; - +import { Controller, Logger, Body } from '@nestjs/common'; import { MessagePattern } from '@nestjs/microservices'; import { EcosystemService } from './ecosystem.service'; -import { Body } from '@nestjs/common'; import { BulkSendInvitationDto } from '../dtos/send-invitation.dto'; import { AcceptRejectEcosystemInvitationDto } from '../dtos/accept-reject-ecosysteminvitation.dto'; import { FetchInvitationsPayload } from '../interfaces/invitations.interface'; import { EcosystemMembersPayload } from '../interfaces/ecosystemMembers.interface'; import { GetEndorsementsPayload, ISchemasResponse } from '../interfaces/endorsements.interface'; -import { IEcosystemDashboard, RequestCredDeffEndorsement, IEcosystem, IEcosystemInvitation, IEcosystemInvitations, IEditEcosystem, IEndorsementTransaction, IEcosystemList, IEcosystemLeadOrgs, IRequestSchemaEndorsement, IRequestW3CSchemaEndorsement } from '../interfaces/ecosystem.interfaces'; +import { IEcosystemDashboard, RequestCredDeffEndorsement, IEcosystem, IEcosystemInvitation, IEcosystemInvitations, IEditEcosystem, IEndorsementTransaction, IEcosystemList, IEcosystemLeadOrgs, IRequestSchemaEndorsement } from '../interfaces/ecosystem.interfaces'; import { IEcosystemDataDeletionResults, IEcosystemDetails } from '@credebl/common/interfaces/ecosystem.interface'; -import { schemaRequestType } from '@credebl/enum/enum'; import { user } from '@prisma/client'; +import { IUserRequestInterface } from 'apps/ledger/src/credential-definition/interfaces'; // eslint-disable-next-line camelcase @Controller() @@ -164,14 +162,13 @@ export class EcosystemController { */ @MessagePattern({ cmd: 'schema-endorsement-request' }) async schemaEndorsementRequest(payload: { - requestSchemaPayload: IRequestSchemaEndorsement | IRequestW3CSchemaEndorsement; - schemaType: schemaRequestType; + requestSchemaPayload: IRequestSchemaEndorsement; + user: user; orgId: string; ecosystemId: string; }): Promise { - const { requestSchemaPayload, schemaType, orgId, ecosystemId } = payload; - - return this.ecosystemService.requestSchemaEndorsement(requestSchemaPayload, schemaType, orgId, ecosystemId); + const { requestSchemaPayload, user, orgId, ecosystemId } = payload; + return this.ecosystemService.requestSchemaEndorsement(requestSchemaPayload, user, orgId, ecosystemId); } /** @@ -209,11 +206,13 @@ export class EcosystemController { * @returns submit endorsement request */ @MessagePattern({ cmd: 'submit-endorsement-transaction' }) - async submitTransaction(payload: { endorsementId: string; ecosystemId: string; orgId: string }): Promise { + async submitTransaction(payload: { endorsementId: string; ecosystemId: string; orgId: string, user: IUserRequestInterface}): Promise { + const { endorsementId, ecosystemId, orgId, user } = payload; return this.ecosystemService.submitTransaction({ - endorsementId: payload.endorsementId, - ecosystemId: payload.ecosystemId, - orgId: payload.orgId + endorsementId, + ecosystemId, + orgId, + user }); } diff --git a/apps/ecosystem/src/ecosystem.service.ts b/apps/ecosystem/src/ecosystem.service.ts index 899b33d84..c368f08bd 100644 --- a/apps/ecosystem/src/ecosystem.service.ts +++ b/apps/ecosystem/src/ecosystem.service.ts @@ -22,7 +22,7 @@ import { EcosystemInviteTemplate } from '../templates/EcosystemInviteTemplate'; import { EmailDto } from '@credebl/common/dtos/email.dto'; import { sendEmail } from '@credebl/common/send-grid-helper-file'; import { AcceptRejectEcosystemInvitationDto } from '../dtos/accept-reject-ecosysteminvitation.dto'; -import { EcosystemConfigSettings, Invitation, OrgAgentType, schemaRequestType, SchemaType } from '@credebl/enum/enum'; +import { EcosystemConfigSettings, Invitation, JSONSchemaType, OrgAgentType, SchemaType, SchemaTypeEnum } from '@credebl/enum/enum'; import { DeploymentModeType, EcosystemOrgStatus, @@ -39,7 +39,6 @@ import { LedgerDetails, OrganizationData, RequestCredDeffEndorsement, - IRequestSchemaEndorsement, SaveSchema, SchemaMessage, SignedTransactionMessage, @@ -53,7 +52,10 @@ import { IEcosystemList, IEcosystemLeadOrgs, IRequestW3CSchemaEndorsement, - ITransactionData + ITransactionData, + IRequestIndySchemaEndorsement, + IRequestSchemaEndorsement, + IschemaPayload } from '../interfaces/ecosystem.interfaces'; import { GetAllSchemaList, GetEndorsementsPayload, ISchemasResponse } from '../interfaces/endorsements.interface'; import { CommonConstants } from '@credebl/common/common.constant'; @@ -75,11 +77,11 @@ import { Cache } from 'cache-manager'; import { CACHE_MANAGER } from '@nestjs/cache-manager'; import { updateEcosystemOrgsDto } from '../dtos/update-ecosystemOrgs.dto'; import { IEcosystemDataDeletionResults, IEcosystemDetails } from '@credebl/common/interfaces/ecosystem.interface'; -import { W3CSchemaPayload } from 'apps/ledger/src/schema/interfaces/schema-payload.interface'; import { OrgRoles } from 'libs/org-roles/enums'; import { DeleteEcosystemMemberTemplate } from '../templates/DeleteEcosystemMemberTemplate'; import { UserActivityRepository } from 'libs/user-activity/repositories'; import { IOrgData } from '@credebl/common/interfaces/organization.interface'; +import { checkDidLedgerAndNetwork } from '@credebl/common/cast.helper'; @Injectable() export class EcosystemService { @@ -169,15 +171,11 @@ export class EcosystemService { return orgData; } - async getEcosystems(orgId: string): Promise { try { return await this.ecosystemRepository.getEcosystemsCount(orgId); } catch (error) { - - this.logger.error( - `[getEcosystemsCount ] [NATS call]- error in get ecosystems count : ${JSON.stringify(error)}` - ); + this.logger.error(`[getEcosystemsCount ] [NATS call]- error in get ecosystems count : ${JSON.stringify(error)}`); throw new RpcException(error.response ? error.response : error); } } @@ -443,9 +441,7 @@ export class EcosystemService { } } - async addOrganizationsInEcosystem( - ecosystemLeadOrgs: IEcosystemLeadOrgs - ): Promise<{ + async addOrganizationsInEcosystem(ecosystemLeadOrgs: IEcosystemLeadOrgs): Promise<{ results: { statusCode: number; message: string; error?: string; data?: { orgId: string } }[]; statusCode: number; message: string; @@ -457,34 +453,37 @@ export class EcosystemService { this.ecosystemRepository.getAllOrganizationsByUserId(ecosystemLeadOrgs.userId), this.ecosystemRepository.getAllOrgRoles() ]); - + const ecosystemLeadOrg = ecosystemDetails?.orgId; const ecosystemLeadOrgLedgerDetails = await this.ecosystemRepository.getAgentDetails(ecosystemLeadOrg); const ecosystemLeadOrgLedgerId = ecosystemLeadOrgLedgerDetails?.ledgerId; - - const ownerRoleId = allOrgRoles.find(role => OrgRoles.OWNER === role.name)?.id; + + const ownerRoleId = allOrgRoles.find((role) => OrgRoles.OWNER === role.name)?.id; const ownerOrganizations = userOrganizations - .filter(org => org.orgRoleId === ownerRoleId) - .map(org => org.orgId); - + .filter((org) => org.orgRoleId === ownerRoleId) + .map((org) => org.orgId); + const { organizationIds } = ecosystemLeadOrgs; const errorOrgs: { statusCode: number; message: string; error?: string; data?: { orgId: string } }[] = []; const addedOrgs = []; let successCount: number = 0; let errorCount: number = 0; - + for (const orgId of organizationIds) { const result: { statusCode: number; message: string; error?: string; data?: { orgId: string } } = { statusCode: 0, message: '' }; - + const orgAgentDetails = await this.ecosystemRepository.getAgentDetails(orgId); const orgLedgerId = orgAgentDetails?.ledgerId; - + if (ownerOrganizations.includes(orgId)) { if (orgAgentDetails?.orgDid) { - const existingOrg = await this.ecosystemRepository.checkOrgExistsInEcosystem(orgId, ecosystemLeadOrgs.ecosystemId); + const existingOrg = await this.ecosystemRepository.checkOrgExistsInEcosystem( + orgId, + ecosystemLeadOrgs.ecosystemId + ); if (orgLedgerId === ecosystemLeadOrgLedgerId) { if (!existingOrg) { addedOrgs.push({ @@ -525,34 +524,34 @@ export class EcosystemService { result.data = { orgId }; errorCount++; } - + if (0 !== result.statusCode) { errorOrgs.push(result); } } - + let statusCode = HttpStatus.CREATED; let message = ResponseMessages.ecosystem.success.add; let getOrgs = []; - + if (0 < addedOrgs?.length) { - const orgs = addedOrgs?.map(item => item.orgId); + const orgs = addedOrgs?.map((item) => item.orgId); await this.ecosystemRepository.addOrganizationInEcosystem(addedOrgs); //need to discuss getOrgs = await this.ecosystemRepository.getEcosystemOrgs(orgs, ecosystemLeadOrgs.ecosystemId); } - + const success = 0 < getOrgs?.length - ? getOrgs?.map(item => ({ + ? getOrgs?.map((item) => ({ statusCode: HttpStatus.CREATED, message: ResponseMessages.ecosystem.success.add, data: { orgId: item.orgId } })) : []; const finalResult = [...errorOrgs, ...success]; - + if (0 === successCount) { statusCode = HttpStatus.BAD_REQUEST; message = ResponseMessages.ecosystem.error.unableToAdd; @@ -560,14 +559,14 @@ export class EcosystemService { statusCode = HttpStatus.PARTIAL_CONTENT; message = ResponseMessages.ecosystem.error.partiallyAdded; } - + return { results: finalResult, statusCode, message }; } catch (error) { this.logger.error(`In add organizations: ${JSON.stringify(error)}`); throw new RpcException(error.response ? error.response : error); } } - + async checkLedgerMatches(orgDetails: OrganizationData, ecosystemId: string): Promise { const orgLedgers = orgDetails.org_agents.map((agent) => agent.ledgers.id); @@ -844,53 +843,79 @@ export class EcosystemService { */ async requestSchemaEndorsement( - requestSchemaPayload: IRequestSchemaEndorsement | IRequestW3CSchemaEndorsement, - schemaType: schemaRequestType, + requestSchemaPayload: IRequestSchemaEndorsement, + user: user, orgId: string, ecosystemId: string ): Promise { - try { + try { const platformConfig = await this.ecosystemRepository.getPlatformConfigDetails(); - if (!platformConfig) { throw new NotFoundException(ResponseMessages.ecosystem.error.platformConfigNotFound); } - + + const agentDetails = await this.ecosystemRepository.getAgentDetails(orgId); + if (!agentDetails) { + throw new NotFoundException(ResponseMessages.schema.error.agentDetailsNotFound, { + cause: new Error(), + description: ResponseMessages.errorMessages.notFound + }); + } + const { schemaPayload, type, endorse } = requestSchemaPayload; + let isSchemaExist; - if (schemaType === schemaRequestType.INDY) { - const { name, version } = requestSchemaPayload as IRequestSchemaEndorsement; - isSchemaExist = await this._schemaExist(name, version); + if (type === SchemaTypeEnum.INDY) { + const indySchema = schemaPayload as IRequestIndySchemaEndorsement; + const { schemaName, schemaVersion } = indySchema; + isSchemaExist = await this._schemaExist(schemaName, schemaVersion); this.logger.log(`isSchemaExist ::: ${JSON.stringify(isSchemaExist.length)}`); - + if (0 !== isSchemaExist.length) { throw new ConflictException(ResponseMessages.ecosystem.error.schemaAlreadyExist); } - - if (0 === name.length) { + + if (0 === schemaName.length) { throw new BadRequestException(ResponseMessages.schema.error.nameNotEmpty); } - - if (0 === version.length) { + + if (0 === schemaVersion.length) { throw new BadRequestException(ResponseMessages.schema.error.versionNotEmpty); } - + const schemaVersionIndexOf = -1; - - if (isNaN(parseFloat(version)) || version.toString().indexOf('.') === schemaVersionIndexOf) { + + if (isNaN(parseFloat(schemaVersion)) || schemaVersion.toString().indexOf('.') === schemaVersionIndexOf) { throw new NotAcceptableException(ResponseMessages.schema.error.invalidVersion); } - return await this.requestIndySchemaEndorsement(requestSchemaPayload as IRequestSchemaEndorsement, orgId, ecosystemId); - } else if (schemaType === schemaRequestType.W3C) { - const { schemaName } = requestSchemaPayload as IRequestW3CSchemaEndorsement; + return await this.requestIndySchemaEndorsement( + schemaPayload as IRequestIndySchemaEndorsement, + orgId, + ecosystemId, + user.id, + endorse + ); + } else if (type === SchemaTypeEnum.JSON) { + const { schemaName, schemaType } = schemaPayload as IRequestW3CSchemaEndorsement; + const ledgerAndNetworkDetails = await checkDidLedgerAndNetwork(schemaType, agentDetails.orgDid); + if (!ledgerAndNetworkDetails) { + throw new BadRequestException(ResponseMessages.schema.error.orgDidAndSchemaType, { + cause: new Error(), + description: ResponseMessages.errorMessages.badRequest + }); + } isSchemaExist = await this._schemaExist(schemaName); if (0 !== isSchemaExist.length) { throw new ConflictException(ResponseMessages.ecosystem.error.schemaNameAlreadyExist); } - return await this.requestW3CSchemaEndorsement(requestSchemaPayload as IRequestW3CSchemaEndorsement, orgId, ecosystemId); + return await this.requestW3CSchemaEndorsement( + schemaPayload as IRequestW3CSchemaEndorsement, + orgId, + ecosystemId, + user.id + ); } - } catch (error) { this.logger.error(`In request schema endorsement : ${JSON.stringify(error)}`); throw new RpcException(error.response ? error.response : error?.error); @@ -898,25 +923,25 @@ export class EcosystemService { } async requestIndySchemaEndorsement( - requestSchemaPayload: IRequestSchemaEndorsement, + requestSchemaPayload: IRequestIndySchemaEndorsement, orgId: string, - ecosystemId: string + ecosystemId: string, + userId: string, + endorse: boolean ): Promise { try { - const getEcosystemLeadDetails = await this.ecosystemRepository.getEcosystemLeadDetails(ecosystemId); - const [ - schemaRequestExist, - ecosystemOrgAgentDetails, - ecosystemLeadAgentDetails, - getEcosystemOrgDetailsByOrgId - ] = await Promise.all([ - this.ecosystemRepository.findRecordsByNameAndVersion(requestSchemaPayload?.name, requestSchemaPayload?.version), - this.ecosystemRepository.getAgentDetails(orgId), - this.ecosystemRepository.getAgentDetails(getEcosystemLeadDetails.orgId), - this.ecosystemRepository.getEcosystemOrgDetailsbyId(orgId, ecosystemId) - ]); + const [schemaRequestExist, ecosystemOrgAgentDetails, ecosystemLeadAgentDetails, getEcosystemOrgDetailsByOrgId] = + await Promise.all([ + this.ecosystemRepository.findRecordsByNameAndVersion( + requestSchemaPayload?.schemaName, + requestSchemaPayload?.schemaVersion + ), + this.ecosystemRepository.getAgentDetails(orgId), + this.ecosystemRepository.getAgentDetails(getEcosystemLeadDetails.orgId), + this.ecosystemRepository.getEcosystemOrgDetailsbyId(orgId, ecosystemId) + ]); const existSchema = schemaRequestExist?.filter( @@ -956,13 +981,13 @@ export class EcosystemService { const schemaTransactionPayload = { endorserDid: ecosystemLeadAgentDetails.orgDid.trim(), - endorse: requestSchemaPayload.endorse, + endorse, attributes: attributeArray, - version: String(requestSchemaPayload.version), - name: requestSchemaPayload.name.trim(), + version: String(requestSchemaPayload.schemaVersion), + name: requestSchemaPayload.schemaName.trim(), issuerId: ecosystemOrgAgentDetails.orgDid.trim() }; - + const schemaTransactionRequest: SchemaMessage = await this._requestSchemaEndorsement( schemaTransactionPayload, url, @@ -975,7 +1000,7 @@ export class EcosystemService { requestPayload: schemaTransactionRequest.message.schemaState.schemaRequest, status: endorsementTransactionStatus.REQUESTED, ecosystemOrgId: getEcosystemOrgDetailsByOrgId.id, - userId: requestSchemaPayload.userId + userId }; if ('failed' === schemaTransactionRequest.message.schemaState.state) { @@ -1000,7 +1025,8 @@ export class EcosystemService { async requestW3CSchemaEndorsement( requestSchemaPayload: IRequestW3CSchemaEndorsement, orgId: string, - ecosystemId: string + ecosystemId: string, + userId: string ): Promise { try { const getEcosystemLeadDetails = await this.ecosystemRepository.getEcosystemLeadDetails(ecosystemId); @@ -1028,7 +1054,7 @@ export class EcosystemService { } if (!ecosystemMemberOrgAgentDetails) { - throw new InternalServerErrorException('Error in fetching agent details'); + throw new InternalServerErrorException('Error in fetching agent details'); } const w3cSchemaTransactionResponse = { @@ -1037,7 +1063,7 @@ export class EcosystemService { requestPayload: JSON.stringify(requestSchemaPayload), status: endorsementTransactionStatus.REQUESTED, ecosystemOrgId: getEcosystemOrgDetailsByOrgId.id, - userId: requestSchemaPayload.userId + userId }; const storeTransaction = await this.ecosystemRepository.storeTransactionRequest( @@ -1050,7 +1076,7 @@ export class EcosystemService { return storeTransaction; } catch (error) { this.logger.error(`In request w3c schema endorsement: ${JSON.stringify(error)}`); - throw error; + throw error; } } @@ -1271,18 +1297,18 @@ export class EcosystemService { async signTransaction(endorsementId: string, ecosystemId: string): Promise { try { - - const checkEndorsementRequestIsSigned = await this.ecosystemRepository.getEndorsementTransactionById( - endorsementId, - endorsementTransactionStatus.SIGNED + const ecosystemDetails = await this.ecosystemRepository.getEcosystemDetails(ecosystemId); + + const checkEndorsementRequestIsExists = await this.ecosystemRepository.getTransactionDetailsByEndorsementId( + endorsementId ); - if (checkEndorsementRequestIsSigned) { + if (checkEndorsementRequestIsExists?.status === endorsementTransactionStatus.SIGNED) { throw new ConflictException(ResponseMessages.ecosystem.error.transactionAlreadySigned); + } else if (checkEndorsementRequestIsExists?.status === endorsementTransactionStatus.SUBMITED) { + throw new ConflictException(ResponseMessages.ecosystem.error.transactionSubmitted); } - const ecosystemDetails = await this.ecosystemRepository.getEcosystemDetails(ecosystemId); - if (!ecosystemDetails) { throw new NotFoundException(ResponseMessages.ecosystem.error.ecosystemNotFound); } @@ -1293,12 +1319,15 @@ export class EcosystemService { this.ecosystemRepository.getPlatformConfigDetails() ]); - if (endorsementTransactionPayload && endorsementTransactionPayload?.type === endorsementTransactionType.W3C_SCHEMA) { - throw new BadRequestException(ResponseMessages.ecosystem.error.signTransactionNotApplicable); + if ( + endorsementTransactionPayload && + endorsementTransactionPayload?.type === endorsementTransactionType.W3C_SCHEMA + ) { + throw new BadRequestException(ResponseMessages.ecosystem.error.signTransactionNotApplicable); } if (!endorsementTransactionPayload) { - throw new InternalServerErrorException(ResponseMessages.ecosystem.error.invalidTransaction); + throw new NotFoundException(ResponseMessages.ecosystem.error.invalidTransaction); } if (!ecosystemLeadDetails) { @@ -1328,46 +1357,45 @@ export class EcosystemService { transaction: jsonString, endorserDid: endorsementTransactionPayload.endorserDid }; - const schemaTransactionRequest: SignedTransactionMessage = await this._signTransaction( - payload, - url, - ecosystemLeadDetails.orgId - ); + const schemaTransactionRequest: SignedTransactionMessage = await this._signTransaction( + payload, + url, + ecosystemLeadDetails.orgId + ); - if (!schemaTransactionRequest) { - throw new InternalServerErrorException(ResponseMessages.ecosystem.error.signRequestError); - } + if (!schemaTransactionRequest) { + throw new InternalServerErrorException(ResponseMessages.ecosystem.error.signRequestError); + } - const updateSignedTransaction = await this.ecosystemRepository.updateTransactionDetails( - endorsementId, - schemaTransactionRequest.message.signedTransaction - ); + const updateSignedTransaction = await this.ecosystemRepository.updateTransactionDetails( + endorsementId, + schemaTransactionRequest.message.signedTransaction + ); - if (!updateSignedTransaction) { - throw new InternalServerErrorException(ResponseMessages.ecosystem.error.updateTransactionError); - } - - if (updateSignedTransaction && true === ecosystemDetails.autoEndorsement) { - const submitTxn = await this.submitTransaction({ - endorsementId, - ecosystemId, - ecosystemLeadAgentEndPoint: ecosystemLeadAgentDetails.agentEndPoint, - orgId: ecosystemLeadDetails.orgId - }); - if (!submitTxn) { - await this.ecosystemRepository.updateTransactionStatus(endorsementId, endorsementTransactionStatus.REQUESTED); - throw new InternalServerErrorException(ResponseMessages.ecosystem.error.sumbitTransaction); - } - const finalResponse = { - autoEndorsement: ecosystemDetails.autoEndorsement, - submitTxn - }; - return finalResponse; + if (!updateSignedTransaction) { + throw new InternalServerErrorException(ResponseMessages.ecosystem.error.updateTransactionError); + } + + if (updateSignedTransaction && true === ecosystemDetails.autoEndorsement) { + const submitTxn = await this.submitTransaction({ + endorsementId, + ecosystemId, + ecosystemLeadAgentEndPoint: ecosystemLeadAgentDetails.agentEndPoint, + orgId: ecosystemLeadDetails.orgId + }); + if (!submitTxn) { + await this.ecosystemRepository.updateTransactionStatus(endorsementId, endorsementTransactionStatus.REQUESTED); + throw new InternalServerErrorException(ResponseMessages.ecosystem.error.sumbitTransaction); } - - await this.removeEndorsementTransactionFields(updateSignedTransaction); - return updateSignedTransaction; + const finalResponse = { + autoEndorsement: ecosystemDetails.autoEndorsement, + submitTxn + }; + return finalResponse; + } + await this.removeEndorsementTransactionFields(updateSignedTransaction); + return updateSignedTransaction; } catch (error) { this.logger.error(`In sign transaction: ${JSON.stringify(error)}`); const errorObject = error?.error; @@ -1479,7 +1507,7 @@ export class EcosystemService { endorsedTransaction: jsonString, endorserDid: ecosystemLeadAgentDetails.orgDid }; - + switch (endorsementTransactionPayload.type) { case endorsementTransactionType.SCHEMA: payload.schema = { @@ -1489,7 +1517,7 @@ export class EcosystemService { issuerId: ecosystemMemberDetails.orgDid }; break; - + case endorsementTransactionType.CREDENTIAL_DEFINITION: payload.credentialDefinition = { tag: parsedRequestPayload.operation.tag, @@ -1502,10 +1530,9 @@ export class EcosystemService { default: throw new Error('Unsupported endorsement transaction type'); } - + return payload; } - async handleSchemaSubmission( endorsementTransactionPayload, @@ -1521,8 +1548,8 @@ export class EcosystemService { extractedDidValue = match[0]; } const saveSchemaPayload: SaveSchema = { - name: endorsementTransactionPayload.requestBody['name'], - version: endorsementTransactionPayload.requestBody['version'], + name: endorsementTransactionPayload.requestBody['schemaName'], + version: endorsementTransactionPayload.requestBody['schemaVersion'], attributes: JSON.stringify(endorsementTransactionPayload.requestBody['attributes']), schemaLedgerId: submitTransactionRequest['message'].schemaId, issuerId: ecosystemMemberDetails.orgDid, @@ -1573,31 +1600,37 @@ export class EcosystemService { return saveCredDefDetails; } - async updateTransactionStatus(endorsementId): Promise { + async updateTransactionStatus(endorsementId: string): Promise { return this.ecosystemRepository.updateTransactionStatus(endorsementId, endorsementTransactionStatus.SUBMITED); } async submitTransaction(transactionPayload: ITransactionData): Promise { try { - const { endorsementId } = transactionPayload; - const checkEndorsementRequestIsSubmitted = await this.ecosystemRepository.getEndorsementTransactionById( - endorsementId, - endorsementTransactionStatus.SUBMITED - ); - if (checkEndorsementRequestIsSubmitted) { + let txnPayload; + + const { endorsementId, orgId, ecosystemId } = transactionPayload; + + const ecosystemLeadDetails = await this.ecosystemRepository.getEcosystemLeadDetails(ecosystemId); + + const endorsementPayload = await this.ecosystemRepository.getTransactionDetailsByEndorsementId(endorsementId); + + const orgIdsToCheck = [ecosystemLeadDetails?.orgId, endorsementPayload?.['ecosystemOrgs']?.orgId]; + + if (!orgIdsToCheck.includes(orgId)) { + throw new ForbiddenException(ResponseMessages.organisation.error.orgNotMatch); + } + + if (endorsementTransactionStatus.SUBMITED === endorsementPayload?.status) { throw new ConflictException(ResponseMessages.ecosystem.error.transactionSubmitted); } - const endorsementPayload = await this.ecosystemRepository.getTransactionDetailsByEndorsementId(endorsementId); - let txnPayload; - if (endorsementPayload?.type === endorsementTransactionType.W3C_SCHEMA) { txnPayload = await this.submitW3CTransaction(transactionPayload); } else { - txnPayload = await this.submitIndyTransaction(transactionPayload); + txnPayload = await this.submitIndyTransaction(transactionPayload); } - return txnPayload; + return txnPayload; } catch (error) { this.logger.error(`In submit transaction: ${JSON.stringify(error)}`); if (error?.error) { @@ -1606,7 +1639,6 @@ export class EcosystemService { message: error?.error?.message, error: error?.error?.error }); - } else { this.handleException(error); } @@ -1718,7 +1750,6 @@ export class EcosystemService { } } - async submitW3CTransaction(transactionPayload: ITransactionData): Promise { try { const { endorsementId } = transactionPayload; @@ -1731,29 +1762,34 @@ export class EcosystemService { throw new BadRequestException(ResponseMessages.ecosystem.error.transactionNotRequested); } - const w3cEndorsementTransactionPayload = await this.ecosystemRepository.getEndorsementTransactionByIdAndType(endorsementId, endorsementTransactionType.W3C_SCHEMA); + const w3cEndorsementTransactionPayload = await this.ecosystemRepository.getEndorsementTransactionByIdAndType( + endorsementId, + endorsementTransactionType.W3C_SCHEMA + ); - const w3cPayload = { - schemaPayload : { - schemaAttributes: w3cEndorsementTransactionPayload?.requestBody?.['schemaAttributes'], - schemaName: w3cEndorsementTransactionPayload?.requestBody?.['schemaName'], - did: w3cEndorsementTransactionPayload?.requestBody?.['did'], - description: w3cEndorsementTransactionPayload?.requestBody?.['description'] + const schemaPayload = { + schemaDetails: { + type: SchemaTypeEnum.JSON, + schemaPayload: { + schemaName: w3cEndorsementTransactionPayload?.requestBody?.['schemaName'], + attributes: w3cEndorsementTransactionPayload?.requestBody?.['attributes'], + schemaType: JSONSchemaType.POLYGON_W3C, + description: w3cEndorsementTransactionPayload?.requestBody?.['description'] + } }, - orgId: w3cEndorsementTransactionPayload?.['ecosystemOrgs']?.orgId, - user: w3cEndorsementTransactionPayload?.requestBody?.['userId'] + orgId: transactionPayload?.orgId, + user: transactionPayload?.user }; - - const w3cSchemaResponse = await this._createW3CSchema(w3cPayload); - + + const w3cSchemaResponse = await this._createW3CSchema(schemaPayload); + const resourceId = w3cSchemaResponse?.['schemaUrl']; - + await this.ecosystemRepository.updateResourse(endorsementId, resourceId); await this.updateTransactionStatus(endorsementId); return w3cSchemaResponse; - } catch (error) { this.logger.error(`In submit w3c transaction: ${JSON.stringify(error)}`); this.handleException(error); @@ -1772,9 +1808,9 @@ export class EcosystemService { throw new RpcException(error.response ? error.response : error); } } - - async _createW3CSchema(payload: W3CSchemaPayload): Promise { - const pattern = { cmd: 'create-w3c-schema' }; + + async _createW3CSchema(payload: IschemaPayload): Promise { + const pattern = { cmd: 'create-schema' }; const w3cSchemaData = await this.ecosystemServiceProxy .send(pattern, payload) @@ -1789,7 +1825,6 @@ export class EcosystemService { error.status ); }); - return w3cSchemaData; } @@ -1826,7 +1861,6 @@ export class EcosystemService { transactionDetails: object ): Promise { try { - // eslint-disable-next-line prefer-destructuring const message = transactionDetails['message']; if (!message) { @@ -2088,10 +2122,7 @@ export class EcosystemService { return userData; } - async deleteOrgFromEcosystem( - orgId: string, - userDetails: user - ): Promise { + async deleteOrgFromEcosystem(orgId: string, userDetails: user): Promise { try { const getEcosystems = await this.ecosystemRepository.getEcosystemsByOrgId(orgId); @@ -2141,7 +2172,7 @@ export class EcosystemService { const getOrgName = await this._getOrgData(orgId); let deleteEcosystems; - + if (getEcosystemMemberRoleOrgIds?.includes(orgId)) { deleteEcosystems = await this.ecosystemRepository.deleteMemberOrgFromEcosystem(orgId); await this.ecosystemRepository.deleteEcosystemInvitations(orgId); @@ -2169,5 +2200,4 @@ export class EcosystemService { throw new RpcException(error.response ? error.response : error); } } - } \ No newline at end of file