Skip to content

Commit

Permalink
feat(trustservice.js): update getAllTrustRelationships
Browse files Browse the repository at this point in the history
Updated `getAllTrustRelationships` for filtered, paginated trust relationships.
  • Loading branch information
Mloweedgar committed Mar 17, 2024
1 parent 8b24f35 commit 27b478c
Showing 1 changed file with 7 additions and 38 deletions.
45 changes: 7 additions & 38 deletions server/services/TrustService.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const Trust = require('../models/Trust');
const Session = require('../infra/database/Session');
const Wallet = require('../models/Wallet');
const WalletService = require('./WalletService');
const EventService = require('./EventService');
const EventEnums = require('../utils/event-enum');
Expand Down Expand Up @@ -35,44 +34,14 @@ class TrustService {
});
}

// limit and offset not feasible using the current implementation
// except if done manually or coming up with a single query
async getAllTrustRelationships({ walletId, state, type, request_type }) {
const walletModel = new Wallet(this._session);
const { wallets } = await walletModel.getAllWallets(
walletId,
undefined,
undefined,
'created_at',
'desc',
);

const alltrustRelationships = [];

await Promise.all(
wallets.map(async (w) => {
const trustRelationships = await this.getTrustRelationships({
walletId: w.id,
state,
type,
request_type,
});
alltrustRelationships.push(...trustRelationships);
}),
);

// remove possible duplicates
const ids = {};
const finalTrustRelationships = [];

alltrustRelationships.forEach((tr) => {
if (!ids[tr.id]) {
finalTrustRelationships.push(tr);
ids[tr.id] = 1;
}
async getAllTrustRelationships({ state, type, request_type, offset, limit }) {
return this._trust.getAllTrustRelationships({
state,
type,
request_type,
offset,
limit,
});

return finalTrustRelationships;
}

async createTrustRelationship({
Expand Down

0 comments on commit 27b478c

Please sign in to comment.