Skip to content

Commit

Permalink
fix: fix get trusts for managed wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
samwel141 committed Jul 11, 2024
1 parent 2e6fa25 commit 3eac2df
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
17 changes: 17 additions & 0 deletions server/handlers/walletHandler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,30 @@ const walletGetTrustRelationships = async (req, res) => {
abortEarly: false,
},
);
const walletService = new WalletService();

const { wallet_id: walletId } = validatedParams;
const { wallet_id: loggedInWalletId } = req;
const sortBy = 'created_at';
const orderBy = 'desc';
const { state, type, request_type, limit, offset, sort_by, order } = validatedQuery;

const { wallets:managedWallets } = await walletService.getAllWallets(
loggedInWalletId,
{
limit:'10',
offset:'0',
},
null,
sortBy,
orderBy,
null,
null
);
const trustService = new TrustService();
const {result: trust_relationships, count: total} = await trustService.getTrustRelationships(
loggedInWalletId,
managedWallets,
{
walletId,
state,
Expand Down
19 changes: 14 additions & 5 deletions server/models/Trust.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Trust {
*/
async getTrustRelationships({
walletId,
managedWallets,
state,
type,
request_type,
Expand All @@ -28,14 +29,22 @@ class Trust {
sort_by,
order,
}) {
const managedWalletIds = managedWallets.map(wallet => wallet.id);
const orConditions = [
{ actor_wallet_id: walletId },
{ target_wallet_id: walletId },
{ originator_wallet_id: walletId },
];

managedWalletIds.forEach((managedWalletId) => {
orConditions.push({ actor_wallet_id: managedWalletId });
orConditions.push({ target_wallet_id: managedWalletId });
orConditions.push({ originator_wallet_id: managedWalletId });
});
const filter = {
and: [
{
or: [
{ actor_wallet_id: walletId },
{ target_wallet_id: walletId },
{ originator_wallet_id: walletId },
],
or: orConditions,
},
],
};
Expand Down
2 changes: 2 additions & 0 deletions server/services/TrustService.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class TrustService {

async getTrustRelationships(
loggedInWalletId,
managedWallets,
{ walletId, state, type, request_type, offset, limit,sort_by, order },
) {
// check if wallet exists first
Expand All @@ -22,6 +23,7 @@ class TrustService {

return this._trust.getTrustRelationships({
walletId,
managedWallets,
state,
type,
request_type,
Expand Down

0 comments on commit 3eac2df

Please sign in to comment.