From 6f0f63330c4e5bc22770a1a3529ab1447fee601d Mon Sep 17 00:00:00 2001 From: tipusinghaw Date: Thu, 27 Jun 2024 16:35:01 +0530 Subject: [PATCH] feat: added support for reuse connection Signed-off-by: tipusinghaw --- .../src/connection/dtos/connection.dto.ts | 4 ++++ apps/connection/src/connection.repository.ts | 17 ++++++++++++++ apps/connection/src/connection.service.ts | 22 ++++++++++++++++--- .../src/interfaces/connection.interfaces.ts | 1 + 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/apps/api-gateway/src/connection/dtos/connection.dto.ts b/apps/api-gateway/src/connection/dtos/connection.dto.ts index 73ef33524..2a8620f33 100644 --- a/apps/api-gateway/src/connection/dtos/connection.dto.ts +++ b/apps/api-gateway/src/connection/dtos/connection.dto.ts @@ -41,6 +41,10 @@ export class CreateOutOfBandConnectionInvitation { @ApiPropertyOptional() @IsOptional() multiUseInvitation?: boolean; + + @ApiPropertyOptional() + @IsOptional() + IsReuseConnection?: boolean; @ApiPropertyOptional() @IsOptional() diff --git a/apps/connection/src/connection.repository.ts b/apps/connection/src/connection.repository.ts index e5d461d34..7c36a4e1c 100644 --- a/apps/connection/src/connection.repository.ts +++ b/apps/connection/src/connection.repository.ts @@ -301,4 +301,21 @@ export class ConnectionRepository { throw error; } } + + // eslint-disable-next-line camelcase + async getInvitationDidByOrgId(orgId: string): Promise { + try { + return this.prisma.agent_invitations.findMany({ + where: { + orgId + }, + orderBy: { + createDateTime: 'asc' + } + }); + } catch (error) { + this.logger.error(`Error in getInvitationDid in connection repository: ${error.message}`); + throw error; + } + } } diff --git a/apps/connection/src/connection.service.ts b/apps/connection/src/connection.service.ts index 73acbf018..5853545c2 100644 --- a/apps/connection/src/connection.service.ts +++ b/apps/connection/src/connection.service.ts @@ -24,6 +24,7 @@ import { CACHE_MANAGER } from '@nestjs/cache-manager'; import { IConnectionList, ICreateConnectionUrl } from '@credebl/common/interfaces/connection.interface'; import { IConnectionDetailsById } from 'apps/api-gateway/src/interfaces/IConnectionSearch.interface'; import { IQuestionPayload } from './interfaces/question-answer.interfaces'; +import { agent_invitations } from '@prisma/client'; @Injectable() export class ConnectionService { @@ -621,7 +622,8 @@ export class ConnectionService { orgId, routing, recipientKey, - invitationDid + invitationDid, + IsReuseConnection } = payload?.createOutOfBandConnectionInvitation; const agentDetails = await this.connectionRepository.getAgentEndPoint(payload?.createOutOfBandConnectionInvitation?.orgId); @@ -631,8 +633,22 @@ export class ConnectionService { if (!agentDetails) { throw new NotFoundException(ResponseMessages.connection.error.agentEndPointNotFound); } + - this.logger.log(`logoUrl:::, ${organisation.logoUrl}`); + let legacyinvitationDid; + if (IsReuseConnection) { + const data: agent_invitations[] = await this.connectionRepository.getInvitationDidByOrgId(orgId); + if (data && 0 < data.length) { + const [firstElement] = data; + legacyinvitationDid = firstElement?.invitationDid ?? undefined; + + this.logger.log('legacyinvitationDid:', legacyinvitationDid); + } + } + const connectionInvitationDid = invitationDid ? invitationDid : legacyinvitationDid; + + this.logger.log('connectionInvitationDid:', connectionInvitationDid); + const connectionPayload = { multiUseInvitation: multiUseInvitation ?? true, autoAcceptConnection: autoAcceptConnection ?? true, @@ -647,7 +663,7 @@ export class ConnectionService { routing: routing || undefined, messages: messages || undefined, recipientKey: recipientKey || undefined, - invitationDid: invitationDid || undefined + invitationDid: connectionInvitationDid || undefined }; const createConnectionInvitationFlag = 'connection-invitation'; diff --git a/apps/connection/src/interfaces/connection.interfaces.ts b/apps/connection/src/interfaces/connection.interfaces.ts index 49f06697a..020e4821d 100644 --- a/apps/connection/src/interfaces/connection.interfaces.ts +++ b/apps/connection/src/interfaces/connection.interfaces.ts @@ -280,6 +280,7 @@ export interface ICreateConnectionInvitation { messages?: object[]; multiUseInvitation?: boolean; autoAcceptConnection?: boolean; + IsReuseConnection?: boolean; routing?: object; appendedAttachments?: object[]; orgId?: string;