diff --git a/apps/connection/src/connection.repository.ts b/apps/connection/src/connection.repository.ts index 2f6b8ecc2..8402647ef 100644 --- a/apps/connection/src/connection.repository.ts +++ b/apps/connection/src/connection.repository.ts @@ -6,6 +6,7 @@ import { IConnectionSearchCriteria, ICreateConnection, OrgAgent } from './interf import { IUserRequest } from '@credebl/user-request/user-request.interface'; import { IConnectionsListCount, IDeletedConnectionsRecord } from '@credebl/common/interfaces/connection.interface'; import { PrismaTables, SortValue } from '@credebl/enum/enum'; +import { ResponseMessages } from '@credebl/common/response-messages'; // import { OrgAgent } from './interfaces/connection.interfaces'; @Injectable() export class ConnectionRepository { @@ -331,9 +332,21 @@ export class ConnectionRepository { .filter(Boolean); if (0 < referencedTables.length) { - throw new ConflictException(`Organization ID ${orgId} is referenced in the following table(s): ${referencedTables.join(', ')}`); + 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}`; + } else if (referencedTables.includes(`${PrismaTables.CREDENTIALS}`)) { + errorMessage += `, ${ResponseMessages.issuance.error.removeIssuanceData}`; + } + } else if (2 === referencedTables.length) { + errorMessage += `, ${ResponseMessages.connection.error.removeConnectionReferences}`; + } + + throw new ConflictException(errorMessage); } - + const getConnectionRecords = await prisma.connections.findMany( { where: { diff --git a/apps/ecosystem/src/ecosystem.service.ts b/apps/ecosystem/src/ecosystem.service.ts index b3b040083..d949c410e 100644 --- a/apps/ecosystem/src/ecosystem.service.ts +++ b/apps/ecosystem/src/ecosystem.service.ts @@ -2128,6 +2128,7 @@ export class EcosystemService { const getOrgName = await this._getOrgData(orgId); let deleteEcosystems; + if (getEcosystemMemberRoleOrgIds?.includes(orgId)) { deleteEcosystems = await this.ecosystemRepository.deleteMemberOrgFromEcosystem(orgId); await this.ecosystemRepository.deleteEcosystemInvitations(orgId); diff --git a/apps/issuance/src/issuance.repository.ts b/apps/issuance/src/issuance.repository.ts index 56962cc38..b504dc283 100644 --- a/apps/issuance/src/issuance.repository.ts +++ b/apps/issuance/src/issuance.repository.ts @@ -546,7 +546,7 @@ export class IssuanceRepository { async deleteIssuanceRecordsByOrgId(orgId: string): Promise { try { - const tablesToCheck = [`${PrismaTables.PRESENTATIONS}`, `${PrismaTables.ECOSYSTEM_ORGS}`]; + const tablesToCheck = [`${PrismaTables.PRESENTATIONS}`]; const referenceCounts = await Promise.all( tablesToCheck.map((table) => this.prisma[table].count({ where: { orgId } })) @@ -562,11 +562,7 @@ export class IssuanceRepository { if (1 === referencedTables.length) { if (referencedTables.includes(`${PrismaTables.PRESENTATIONS}`)) { errorMessage += `, ${ResponseMessages.verification.error.removeVerificationData}`; - } else if (referencedTables.includes(`${PrismaTables.ECOSYSTEM_ORGS}`)) { - errorMessage += `, ${ResponseMessages.ecosystem.error.removeEcosystemData}`; - } - } else if (2 === referencedTables.length) { - errorMessage += ', first you have to remove verification data and ecosystem data'; + } } throw new ConflictException(errorMessage); diff --git a/apps/verification/src/repositories/verification.repository.ts b/apps/verification/src/repositories/verification.repository.ts index cbeecf14b..1060ae05e 100644 --- a/apps/verification/src/repositories/verification.repository.ts +++ b/apps/verification/src/repositories/verification.repository.ts @@ -1,12 +1,12 @@ import { ResponseMessages } from '@credebl/common/response-messages'; import { PrismaService } from '@credebl/prisma-service'; -import { ConflictException, Injectable, Logger, NotFoundException } from '@nestjs/common'; +import { Injectable, Logger, NotFoundException } from '@nestjs/common'; // eslint-disable-next-line camelcase import { agent_invitations, org_agents, organisation, platform_config, presentations } from '@prisma/client'; import { IProofPresentation, IProofRequestSearchCriteria } from '../interfaces/verification.interface'; import { IUserRequest } from '@credebl/user-request/user-request.interface'; import { IProofPresentationsListCount, IVerificationRecords } from '@credebl/common/interfaces/verification.interface'; -import { PrismaTables, SortValue } from '@credebl/enum/enum'; +import { SortValue } from '@credebl/enum/enum'; @Injectable() export class VerificationRepository { @@ -234,20 +234,6 @@ export class VerificationRepository { async deleteVerificationRecordsByOrgId(orgId: string): Promise { try { - const tablesToCheck = [`${PrismaTables.ECOSYSTEM_ORGS}`]; - - const referenceCounts = await Promise.all( - tablesToCheck.map((table) => this.prisma[table].count({ where: { orgId } })) - ); - - const referencedTables = referenceCounts - .map((count, index) => (0 < count ? tablesToCheck[index] : null)) - .filter(Boolean); - - if (0 < referencedTables.length) { - throw new ConflictException(`Organization ID ${orgId} is referenced in the following table(s): ${referencedTables.join(', ')}, first you have to remove ecosystem data`); - } - return await this.prisma.$transaction(async (prisma) => { const recordsToDelete = await this.prisma.presentations.findMany({ diff --git a/libs/common/src/response-messages/index.ts b/libs/common/src/response-messages/index.ts index 6599eaa7e..6457cfaa7 100644 --- a/libs/common/src/response-messages/index.ts +++ b/libs/common/src/response-messages/index.ts @@ -274,7 +274,8 @@ export const ResponseMessages = { connectionNotFound: 'Connection not found', agentEndPointNotFound: 'agentEndPoint Not Found', agentUrlNotFound: 'agent url not found', - connectionRecordNotFound: 'Connection records does not exists' + connectionRecordNotFound: 'Connection records does not exists', + removeConnectionReferences: 'First you have to remove credentials data and verification data' } }, issuance: { @@ -321,7 +322,8 @@ export const ResponseMessages = { missingRequestId: 'Param requestId is missing from the request.', cachedData: 'Cached data does not exist', cachedfileData: 'Cached file data does not exist', - issuanceRecordsNotFound: 'Issuance records does not exists' + issuanceRecordsNotFound: 'Issuance records does not exists', + removeIssuanceData: 'First you have to remove issuance data' } }, verification: { @@ -429,8 +431,7 @@ export const ResponseMessages = { orgEcoIdRequired: 'OrgId & EcosystemId is required', ecosystemMembersNotExists: 'Ecosystem members does not exists', notAbleToDeleteEcosystem: 'You cannot delete the ecosystem, because you are the ecosystem lead', - ecosystemNotExists: 'Ecosystem does not exists', - removeEcosystemData: 'First you have to remove ecosystem data' + ecosystemNotExists: 'Ecosystem does not exists' } }, bulkIssuance: {