From 5e474cd192daca060d3551e85f289b4d3b250c86 Mon Sep 17 00:00:00 2001 From: Ankita Patidar Date: Wed, 15 Oct 2025 12:14:52 +0530 Subject: [PATCH 1/2] fix: minimize data while getting connection Signed-off-by: Ankita Patidar --- apps/connection/src/connection.repository.ts | 53 +++++++++----------- apps/connection/src/connection.service.ts | 17 +++---- 2 files changed, 30 insertions(+), 40 deletions(-) diff --git a/apps/connection/src/connection.repository.ts b/apps/connection/src/connection.repository.ts index ec43c8385..474993b43 100644 --- a/apps/connection/src/connection.repository.ts +++ b/apps/connection/src/connection.repository.ts @@ -90,7 +90,6 @@ export class ConnectionRepository { } } - async getConnectionRecordsCount(orgId: string): Promise { try { const connectionRecordsCount = await this.prisma.connections.count({ @@ -105,7 +104,6 @@ export class ConnectionRepository { } } - /** * Description: Save connection details * @param connectionInvitation @@ -333,7 +331,7 @@ export class ConnectionRepository { if (0 < referencedTables.length) { let errorMessage = `Organization ID ${orgId} is referenced in the following table(s): ${referencedTables.join(', ')}`; - + if (1 === referencedTables.length) { if (referencedTables.includes(`${PrismaTables.PRESENTATIONS}`)) { errorMessage += `, ${ResponseMessages.verification.error.removeVerificationData}`; @@ -343,34 +341,31 @@ export class ConnectionRepository { } else if (2 === referencedTables.length) { errorMessage += `, ${ResponseMessages.connection.error.removeConnectionReferences}`; } - + throw new ConflictException(errorMessage); } - - const getConnectionRecords = await prisma.connections.findMany( - { - where: { - orgId - }, - select: { - createDateTime: true, - createdBy: true, - connectionId: true, - theirLabel: true, - state: true, - orgId: true - } - }); + const getConnectionRecords = await prisma.connections.findMany({ + where: { + orgId + }, + select: { + createDateTime: true, + createdBy: true, + connectionId: true, + theirLabel: true, + state: true, + orgId: true + } + }); - const deleteConnectionRecords = await prisma.connections.deleteMany( - { - where: { - orgId - } - }); + const deleteConnectionRecords = await prisma.connections.deleteMany({ + where: { + orgId + } + }); - return {getConnectionRecords, deleteConnectionRecords }; + return { getConnectionRecords, deleteConnectionRecords }; }); } catch (error) { this.logger.error(`Error in deleting connection records: ${error.message}`); @@ -378,10 +373,10 @@ export class ConnectionRepository { } } - // eslint-disable-next-line camelcase - async getInvitationDidByOrgId(orgId: string): Promise { + // eslint-disable-next-line camelcase + async getInvitationDidByOrgId(orgId: string): Promise { try { - return this.prisma.agent_invitations.findMany({ + return this.prisma.agent_invitations.findFirst({ where: { orgId }, diff --git a/apps/connection/src/connection.service.ts b/apps/connection/src/connection.service.ts index 8442c7421..5cb446e36 100644 --- a/apps/connection/src/connection.service.ts +++ b/apps/connection/src/connection.service.ts @@ -528,21 +528,16 @@ export class ConnectionService { throw new NotFoundException(ResponseMessages.connection.error.agentEndPointNotFound); } - let legacyinvitationDid; + 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 data: agent_invitations = await this.connectionRepository.getInvitationDidByOrgId(orgId); + legacyInvitationDid = data.invitationDid ?? undefined; } - const connectionInvitationDid = invitationDid ? invitationDid : legacyinvitationDid; + const connectionInvitationDid = invitationDid ? invitationDid : legacyInvitationDid; - this.logger.log('connectionInvitationDid:', connectionInvitationDid); + this.logger.debug('connectionInvitationDid:', connectionInvitationDid); - this.logger.log(`logoUrl:::, ${organisation.logoUrl}`); + this.logger.debug(`logoUrl:::, ${organisation.logoUrl}`); const connectionPayload = { multiUseInvitation: multiUseInvitation ?? true, autoAcceptConnection: autoAcceptConnection ?? true, From a56a8b19d88dc02845bf0e53068118d2ff39c90a Mon Sep 17 00:00:00 2001 From: Ankita Patidar Date: Mon, 17 Nov 2025 13:08:03 +0530 Subject: [PATCH 2/2] fix: potential runtime crash Signed-off-by: Ankita Patidar --- apps/connection/src/connection.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/connection/src/connection.service.ts b/apps/connection/src/connection.service.ts index 5cb446e36..431699b11 100644 --- a/apps/connection/src/connection.service.ts +++ b/apps/connection/src/connection.service.ts @@ -528,12 +528,12 @@ export class ConnectionService { throw new NotFoundException(ResponseMessages.connection.error.agentEndPointNotFound); } - let legacyInvitationDid; + let legacyInvitationDid: string | undefined; if (IsReuseConnection) { const data: agent_invitations = await this.connectionRepository.getInvitationDidByOrgId(orgId); - legacyInvitationDid = data.invitationDid ?? undefined; + legacyInvitationDid = data?.invitationDid ?? undefined; } - const connectionInvitationDid = invitationDid ? invitationDid : legacyInvitationDid; + const connectionInvitationDid = invitationDid ?? legacyInvitationDid; this.logger.debug('connectionInvitationDid:', connectionInvitationDid);