From c4592816ac2c9938ca4bd104f7660379e123111c Mon Sep 17 00:00:00 2001 From: Pranav Kakaraparti Date: Wed, 9 Aug 2023 23:46:59 -0500 Subject: [PATCH] feat: removed getcount param for transfers --- server/handlers/transferHandler/index.js | 9 ++++++++- server/models/Transfer.js | 11 +++++------ server/repositories/TransferRepository.js | 7 ++----- server/services/TransferService.js | 5 ++--- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/server/handlers/transferHandler/index.js b/server/handlers/transferHandler/index.js index 930a8120..4be7df4a 100644 --- a/server/handlers/transferHandler/index.js +++ b/server/handlers/transferHandler/index.js @@ -95,7 +95,14 @@ const transferIdGet = async (req, res) => { req.params.transfer_id, req.wallet_id, ); - res.json(result); + + const modifiedTransfer = { + ...result, + token_count: + +result.parameters?.bundle?.bundleSize || +result.parameters?.tokens?.length, + } + + res.json(modifiedTransfer); }; const transferIdTokenGet = async (req, res) => { diff --git a/server/models/Transfer.js b/server/models/Transfer.js index 442cd5e6..d5e5df35 100644 --- a/server/models/Transfer.js +++ b/server/models/Transfer.js @@ -26,20 +26,20 @@ class Transfer { return transferObjectCopy; } - async getByFilter(filter, limitOptions, getCount) { - const {count, result} = await this._transferRepository.getByFilter( + async getByFilter(filter, limitOptions) { + const {result, count} = await this._transferRepository.getByFilter( filter, limitOptions, - getCount ); + const transfers = result.map((t) => this.constructor.removeWalletIds(t)); return { transfers, count } } async getById({ transferId, walletLoginId }) { - const transfers = await this.getTransfers({ walletLoginId, transferId }); + const {transfers} = await this.getTransfers({ walletLoginId, transferId }); return transfers[0]; } @@ -65,7 +65,6 @@ class Transfer { transferId, before, after, - getCount }) { const filter = { and: [], @@ -98,7 +97,7 @@ class Transfer { if (after) { filter.and.push({ after: { 'transfer.created_at': after } }); } - return this.getByFilter(filter, { offset, limit }, getCount); + return this.getByFilter(filter, { offset, limit }); } /* diff --git a/server/repositories/TransferRepository.js b/server/repositories/TransferRepository.js index 3c3031d8..73c7740e 100644 --- a/server/repositories/TransferRepository.js +++ b/server/repositories/TransferRepository.js @@ -93,7 +93,7 @@ class TransferRepository extends BaseRepository { return transfer; } - async getByFilter(filter, limitOptions, getCount) { + async getByFilter(filter, limitOptions) { let promise = this._session .getDB() .select( @@ -136,10 +136,7 @@ class TransferRepository extends BaseRepository { const result = await promise; Joi.assert(result, Joi.array().required()); - if (getCount) - return { result, count: +count[0].count }; - - return result; + return { result, count: +count[0].count }; } async getPendingTransfers(wallet_id) { diff --git a/server/services/TransferService.js b/server/services/TransferService.js index 2d4970dc..adba2835 100644 --- a/server/services/TransferService.js +++ b/server/services/TransferService.js @@ -13,7 +13,7 @@ class TransferService { } async getByFilter(query, walletLoginId) { - const { state, wallet, limit, offset, before, after, getCount = true } = query; + const { state, wallet, limit, offset, before, after } = query; let walletId; @@ -29,8 +29,7 @@ class TransferService { limit, walletLoginId, before, - after, - getCount + after });