diff --git a/apps/agent-service/src/agent-service.service.ts b/apps/agent-service/src/agent-service.service.ts index e5279da23..3f35cfa9d 100644 --- a/apps/agent-service/src/agent-service.service.ts +++ b/apps/agent-service/src/agent-service.service.ts @@ -863,12 +863,10 @@ export class AgentServiceService { } delete createDidPayload.isPrimaryDid; + + const didDetails = await this.commonService.httpPost(url, createDidPayload, { headers: { authorization: getApiKey } }); - const didDetails = await this.commonService.httpPost(url, createDidPayload, { - headers: { authorization: getApiKey } - }); - - if (!didDetails) { + if (!didDetails || Object.keys(didDetails).length === 0) { throw new InternalServerErrorException(ResponseMessages.agent.error.createDid, { cause: new Error(), description: ResponseMessages.errorMessages.serverError @@ -877,7 +875,7 @@ export class AgentServiceService { const createdDidDetails = { orgId, did: didDetails.did, - didDocument: didDetails.didDocument, + didDocument: didDetails.didDocument || didDetails.didDoc, isPrimaryDid, orgAgentId: agentDetails.id, userId: user.id diff --git a/apps/api-gateway/src/organization/organization.controller.ts b/apps/api-gateway/src/organization/organization.controller.ts index 772c7b028..afbe01717 100644 --- a/apps/api-gateway/src/organization/organization.controller.ts +++ b/apps/api-gateway/src/organization/organization.controller.ts @@ -360,11 +360,10 @@ export class OrganizationController { @UseGuards(AuthGuard('jwt'), OrgRolesGuard) @ApiBearerAuth() async setPrimaryDid(@Param('orgId') orgId: string, @Body() primaryDidPayload: PrimaryDid, @Res() res: Response): Promise { - const orgData = await this.organizationService.setPrimaryDid(primaryDidPayload, orgId); + await this.organizationService.setPrimaryDid(primaryDidPayload, orgId); const finalResponse: IResponse = { statusCode: HttpStatus.CREATED, - message: ResponseMessages.organisation.success.primaryDid, - data: orgData + message: ResponseMessages.organisation.success.primaryDid }; return res.status(HttpStatus.CREATED).json(finalResponse); } diff --git a/apps/api-gateway/src/verification/dto/request-proof.dto.ts b/apps/api-gateway/src/verification/dto/request-proof.dto.ts index cf0642766..c1d27565e 100644 --- a/apps/api-gateway/src/verification/dto/request-proof.dto.ts +++ b/apps/api-gateway/src/verification/dto/request-proof.dto.ts @@ -202,15 +202,17 @@ export class RequestProofDto extends ProofPayload { @ApiProperty({ 'example': { - 'indy': [ - { + 'indy': { + 'attributes': [ + { attributeName: 'attributeName', condition: '>=', value: 'predicates', credDefId: 'string', schemaId: 'string' - } - ] + } + ] + } }, type: () => [IndyDto] }) diff --git a/apps/organization/interfaces/organization.interface.ts b/apps/organization/interfaces/organization.interface.ts index 150e0d7ba..ead9a642e 100644 --- a/apps/organization/interfaces/organization.interface.ts +++ b/apps/organization/interfaces/organization.interface.ts @@ -170,4 +170,9 @@ export interface IDidDetails { did: string; didDocument: Prisma.JsonValue; orgAgentId: string; +} + +export interface IPrimaryDidDetails extends IPrimaryDid { + id: string, + didDocument: Prisma.JsonValue } \ No newline at end of file diff --git a/apps/organization/repositories/organization.repository.ts b/apps/organization/repositories/organization.repository.ts index 31f7e3474..4759e8bb1 100644 --- a/apps/organization/repositories/organization.repository.ts +++ b/apps/organization/repositories/organization.repository.ts @@ -6,7 +6,7 @@ import { Injectable, Logger, NotFoundException } from '@nestjs/common'; import { Prisma, agent_invitations, org_agents, org_invitations, user_org_roles } from '@prisma/client'; import { CreateOrganizationDto } from '../dtos/create-organization.dto'; -import { IDidDetails, IDidList, IGetOrgById, IGetOrganization, IUpdateOrganization } from '../interfaces/organization.interface'; +import { IDidDetails, IDidList, IGetOrgById, IGetOrganization, IPrimaryDidDetails, IUpdateOrganization } from '../interfaces/organization.interface'; import { InternalServerErrorException } from '@nestjs/common'; import { Invitation, SortValue } from '@credebl/enum/enum'; import { PrismaService } from '@credebl/prisma-service'; @@ -779,8 +779,9 @@ export class OrganizationRepository { } } - async setOrgsPrimaryDid(primaryDid:string, orgId:string, id:string): Promise { + async setOrgsPrimaryDid(primaryDidDetails: IPrimaryDidDetails): Promise { try { + const {did, didDocument, id, orgId} = primaryDidDetails; await this.prisma.$transaction([ this.prisma.org_dids.update({ where: { @@ -790,13 +791,13 @@ export class OrganizationRepository { isPrimaryDid: true } }), - this.prisma.org_agents.update({ where: { orgId }, data: { - orgDid: primaryDid + orgDid: did, + didDocument } }) ]); @@ -807,6 +808,19 @@ export class OrganizationRepository { } } +async getDidDetailsByDid(did:string): Promise { + try { + return this.prisma.org_dids.findFirstOrThrow({ + where: { + did + } + }); + } catch (error) { + this.logger.error(`[getDidDetailsByDid] - get DID details: ${JSON.stringify(error)}`); + throw error; + } + } + async getPerviousPrimaryDid(orgId:string): Promise { try { return this.prisma.org_dids.findFirstOrThrow({ diff --git a/apps/organization/src/organization.service.ts b/apps/organization/src/organization.service.ts index 6ab504827..a3e3ad56f 100644 --- a/apps/organization/src/organization.service.ts +++ b/apps/organization/src/organization.service.ts @@ -27,7 +27,7 @@ import { CreateOrganizationDto } from '../dtos/create-organization.dto'; import { BulkSendInvitationDto } from '../dtos/send-invitation.dto'; import { UpdateInvitationDto } from '../dtos/update-invitation.dt'; import { Invitation, OrgAgentType, transition } from '@credebl/enum/enum'; -import { IGetOrgById, IGetOrganization, IUpdateOrganization, IOrgAgent, IClientCredentials, ICreateConnectionUrl, IOrgRole, IDidList } from '../interfaces/organization.interface'; +import { IGetOrgById, IGetOrganization, IUpdateOrganization, IOrgAgent, IClientCredentials, ICreateConnectionUrl, IOrgRole, IDidList, IPrimaryDidDetails } from '../interfaces/organization.interface'; import { UserActivityService } from '@credebl/user-activity'; import { CommonConstants } from '@credebl/common/common.constant'; import { ClientRegistrationService } from '@credebl/client-registration/client-registration.service'; @@ -175,17 +175,28 @@ export class OrganizationService { if (orgAgentDetails.orgDid === did) { throw new ConflictException(ResponseMessages.organisation.error.primaryDid); } - + //check user DID exist in the organization's did list const organizationDidList = await this.organizationRepository.getAllOrganizationDid(orgId); const isDidMatch = organizationDidList.some(item => item.did === did); if (!isDidMatch) { throw new NotFoundException(ResponseMessages.organisation.error.didNotFound); } + const didDetails = await this.organizationRepository.getDidDetailsByDid(did); - const getExistingPrimaryDid = await this.organizationRepository.getPerviousPrimaryDid(orgId); + if (!didDetails) { + throw new NotFoundException(ResponseMessages.organisation.error.didNotFound); + } + const primaryDidDetails: IPrimaryDidDetails = { + did, + orgId, + id, + didDocument: didDetails.didDocument + }; - const setPrimaryDid = await this.organizationRepository.setOrgsPrimaryDid(did, orgId, id); + const setPrimaryDid = await this.organizationRepository.setOrgsPrimaryDid(primaryDidDetails); + + const getExistingPrimaryDid = await this.organizationRepository.getPerviousPrimaryDid(orgId); if (!getExistingPrimaryDid) {