Skip to content

Commit

Permalink
feat: reuse connection usinginvitation DID (#940)
Browse files Browse the repository at this point in the history
Signed-off-by: tipusinghaw <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>
  • Loading branch information
tipusinghaw authored and KulkarniShashank committed Sep 12, 2024
1 parent 58a2165 commit 30178f5
Show file tree
Hide file tree
Showing 4 changed files with 46 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 @@ -377,4 +377,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;
}
}
}
27 changes: 24 additions & 3 deletions apps/connection/src/connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { IConnectionDetailsById } from 'apps/api-gateway/src/interfaces/IConnect
import { IQuestionPayload } from './interfaces/question-answer.interfaces';
import { RecordType, user } from '@prisma/client';
import { UserActivityRepository } from 'libs/user-activity/repositories';
import { agent_invitations } from '@prisma/client';
@Injectable()
export class ConnectionService {
constructor(
Expand Down Expand Up @@ -692,8 +693,11 @@ export class ConnectionService {
messages,
multiUseInvitation,
orgId,
routing
} = createOutOfBandConnectionInvitation;
routing,
recipientKey,
invitationDid,
IsReuseConnection
} = payload?.createOutOfBandConnectionInvitation;

const agentDetails = await this.connectionRepository.getAgentEndPoint(
payload?.createOutOfBandConnectionInvitation?.orgId
Expand All @@ -704,6 +708,23 @@ export class ConnectionService {
if (!agentDetails) {
throw new NotFoundException(ResponseMessages.connection.error.agentEndPointNotFound);
}

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);


this.logger.log(`logoUrl:::, ${organisation.logoUrl}`);
const connectionPayload = {
multiUseInvitation: multiUseInvitation ?? true,
autoAcceptConnection: autoAcceptConnection ?? true,
Expand All @@ -718,7 +739,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 @@ -279,6 +279,7 @@ export interface ICreateConnectionInvitation {
messages?: object[];
multiUseInvitation?: boolean;
autoAcceptConnection?: boolean;
IsReuseConnection?: boolean;
routing?: object;
appendedAttachments?: object[];
orgId?: string;
Expand Down

0 comments on commit 30178f5

Please sign in to comment.