Skip to content

Commit

Permalink
Merge pull request #348 from credebl/339-ecosystem-ledger-restrictions
Browse files Browse the repository at this point in the history
refactor: ecosystem ledger restrictions
  • Loading branch information
KulkarniShashank authored Dec 14, 2023
2 parents abcda45 + 425cd9a commit ad17250
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions apps/ecosystem/src/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class EcosystemService {

if (tags) { updateData.tags = tags; }

if (logo) { updateData.logo = tags; }
if (logo) { updateData.logo = logo; }

if ('' !== autoEndorsement.toString()) { updateData.autoEndorsement = autoEndorsement; }

Expand Down Expand Up @@ -301,6 +301,24 @@ export class EcosystemService {
}
}

async checkLedgerMatches(orgDetails: OrganizationData, ecosystemId: string): Promise<boolean> {
const orgLedgers = orgDetails.org_agents.map((agent) => agent.ledgers.id);

const ecosystemDetails = await this.ecosystemRepository.getEcosystemDetails(ecosystemId);

let isLedgerFound = false;

for (const ledger of orgLedgers) {
// Check if the ledger is present in the ecosystem
if (Array.isArray(ecosystemDetails.ledgers) && ecosystemDetails.ledgers.includes(ledger)) {
// If a ledger is found, return true
isLedgerFound = true;
}
}

return isLedgerFound;
}

/**
*
* @param acceptRejectEcosystemInvitation
Expand Down Expand Up @@ -336,21 +354,9 @@ export class EcosystemService {
throw new NotFoundException(ResponseMessages.ecosystem.error.orgDidNotExist);
}

const orgLedgers = orgDetails.org_agents.map((agent) => agent.ledgers.id);

const ecosystemDetails = await this.ecosystemRepository.getEcosystemDetails(invitation.ecosystemId);

let isLedgerFound = false;

for (const ledger of orgLedgers) {
// Check if the ledger is present in the ecosystem
if (Array.isArray(ecosystemDetails.ledgers) && ecosystemDetails.ledgers.includes(ledger)) {
// If a ledger is found, return true
isLedgerFound = true;
}
}
const isLedgerFound = await this.checkLedgerMatches(orgDetails, invitation.ecosystemId);

if (!isLedgerFound) {
if (!isLedgerFound && Invitation.REJECTED !== status) {
throw new NotFoundException(ResponseMessages.ecosystem.error.ledgerNotMatch);
}

Expand Down

0 comments on commit ad17250

Please sign in to comment.