Skip to content

Commit

Permalink
Feat/delete ecosystem members (#795)
Browse files Browse the repository at this point in the history
* feat: delete ecosystem members

Signed-off-by: bhavanakarwade <[email protected]>

* wip: delete ecosystem

Signed-off-by: bhavanakarwade <[email protected]>

* fix: eslint issues

Signed-off-by: bhavanakarwade <[email protected]>

* fix: resolved trimmedstring issue

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: interface type

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: get organization details function

Signed-off-by: bhavanakarwade <[email protected]>

* fix: resolved conflicts

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: made description field required

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: function name

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: function name

Signed-off-by: bhavanakarwade <[email protected]>

* fix: function name changes

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: references table conditions

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: enum type

Signed-off-by: bhavanakarwade <[email protected]>

---------

Signed-off-by: bhavanakarwade <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>
  • Loading branch information
bhavanakarwade authored and KulkarniShashank committed Sep 12, 2024
1 parent f905cd2 commit afbaf52
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
17 changes: 15 additions & 2 deletions apps/connection/src/connection.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions apps/ecosystem/src/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 2 additions & 6 deletions apps/issuance/src/issuance.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ export class IssuanceRepository {

async deleteIssuanceRecordsByOrgId(orgId: string): Promise<IDeletedIssuanceRecords> {
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 } }))
Expand All @@ -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);
Expand Down
18 changes: 2 additions & 16 deletions apps/verification/src/repositories/verification.repository.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -234,20 +234,6 @@ export class VerificationRepository {

async deleteVerificationRecordsByOrgId(orgId: string): Promise<IVerificationRecords> {
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({
Expand Down
9 changes: 5 additions & 4 deletions libs/common/src/response-messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit afbaf52

Please sign in to comment.