Skip to content

Commit

Permalink
fix: query count condition
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkparti committed Sep 12, 2023
1 parent 35cb0a3 commit cc7cdc0
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions server/repositories/WalletRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ 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('*');

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

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

const wallets = await query;
Joi.assert(wallets, Joi.array().required());

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

return { wallets };
}
Expand Down

0 comments on commit cc7cdc0

Please sign in to comment.