Skip to content

Commit

Permalink
feat: added support for reuse connection
Browse files Browse the repository at this point in the history
Signed-off-by: tipusinghaw <[email protected]>
  • Loading branch information
tipusinghaw committed Jun 27, 2024
1 parent 3676d8c commit 6f0f633
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
4 changes: 4 additions & 0 deletions apps/api-gateway/src/connection/dtos/connection.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export class CreateOutOfBandConnectionInvitation {
@ApiPropertyOptional()
@IsOptional()
multiUseInvitation?: boolean;

@ApiPropertyOptional()
@IsOptional()
IsReuseConnection?: boolean;

@ApiPropertyOptional()
@IsOptional()
Expand Down
17 changes: 17 additions & 0 deletions apps/connection/src/connection.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,21 @@ export class ConnectionRepository {
throw error;
}
}

// eslint-disable-next-line camelcase
async getInvitationDidByOrgId(orgId: string): Promise<agent_invitations[]> {
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;
}
}
}
22 changes: 19 additions & 3 deletions apps/connection/src/connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -621,7 +622,8 @@ export class ConnectionService {
orgId,
routing,
recipientKey,
invitationDid
invitationDid,
IsReuseConnection
} = payload?.createOutOfBandConnectionInvitation;

const agentDetails = await this.connectionRepository.getAgentEndPoint(payload?.createOutOfBandConnectionInvitation?.orgId);
Expand All @@ -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,
Expand All @@ -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';
Expand Down
1 change: 1 addition & 0 deletions apps/connection/src/interfaces/connection.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ export interface ICreateConnectionInvitation {
messages?: object[];
multiUseInvitation?: boolean;
autoAcceptConnection?: boolean;
IsReuseConnection?: boolean;
routing?: object;
appendedAttachments?: object[];
orgId?: string;
Expand Down

0 comments on commit 6f0f633

Please sign in to comment.