Skip to content

Commit

Permalink
fix: get /wallets returns correct pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkparti committed Sep 5, 2023
1 parent 00d5fa2 commit d9b2294
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions server/repositories/WalletRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ class WalletRepository extends BaseRepository {

query = query.union(union1, union2);

// get the total count (before applying limit and offset options)
const count = await this._session.getDB().from(query.as('p')).count('*');

if (limitOptions && limitOptions.limit) {
query = query.limit(limitOptions.limit);
}
Expand All @@ -107,11 +110,10 @@ class WalletRepository extends BaseRepository {
}

const wallets = await query;
if (getCount) {
const count = await this._session.getDB().from(query.as('p')).count('*');
Joi.assert(wallets, Joi.array().required());

if(getCount)
return { wallets, count: +count[0].count };
}

return { wallets };
}
Expand Down

0 comments on commit d9b2294

Please sign in to comment.