From d9b2294cea190d1bb190dd3a5fa1d065fbb06e04 Mon Sep 17 00:00:00 2001 From: Pranav Kakaraparti Date: Tue, 5 Sep 2023 18:52:43 -0500 Subject: [PATCH] fix: get /wallets returns correct pagination --- server/repositories/WalletRepository.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/repositories/WalletRepository.js b/server/repositories/WalletRepository.js index a6e9d70e..0a8583e0 100644 --- a/server/repositories/WalletRepository.js +++ b/server/repositories/WalletRepository.js @@ -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); } @@ -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 }; }