From 23d4a25d33fdd48f9bd21e6934da687fece49b15 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Thu, 16 Jul 2026 11:30:16 +0300 Subject: [PATCH 1/4] Optimize providing additional filtering props --- .../find-in-coll-by/get-filter-params.js | 35 ++++++++++++------- .../get-insertable-array-objects-filter.js | 4 +-- .../dao/helpers/get-status-messages-filter.js | 4 +-- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/workers/loc.api/sync/dao/helpers/find-in-coll-by/get-filter-params.js b/workers/loc.api/sync/dao/helpers/find-in-coll-by/get-filter-params.js index d81ca194e..fb7f27568 100644 --- a/workers/loc.api/sync/dao/helpers/find-in-coll-by/get-filter-params.js +++ b/workers/loc.api/sync/dao/helpers/find-in-coll-by/get-filter-params.js @@ -11,6 +11,9 @@ const getStatusMessagesFilter = require( '../get-status-messages-filter' ) const TABLES_NAMES = require('../../../schema/tables-names') +const SUPPORTED_MODEL_FIELDS = require( + '../../../schema/sync-schema/model/supported.model.fields' +) module.exports = (args, methodColl, opts) => { const { auth, params } = { ...args } @@ -28,25 +31,31 @@ module.exports = (args, methodColl, opts) => { const filter = { ...insertableArrayObjectsFilter, - ...statusMessagesfilter + ...statusMessagesfilter, + ...methodColl[SUPPORTED_MODEL_FIELDS.ADDITIONAL_FILTERING_PROPS] } - if (!isPublic) { - const { _id, isSubAccount } = { ...auth } - - if (!Number.isInteger(_id)) { - throw new AuthError() - } - if ( - methodColl.getModelField('NAME') === TABLES_NAMES.LEDGERS && - isSubAccount - ) { - filter._isBalanceRecalced = 1 + if (isPublic) { + return { + requestedFilter, + filter } + } - filter.user_id = _id + const { _id, isSubAccount } = auth ?? {} + + if (!Number.isInteger(_id)) { + throw new AuthError() + } + if ( + methodColl.getModelField('NAME') === TABLES_NAMES.LEDGERS && + isSubAccount + ) { + filter._isBalanceRecalced = 1 } + filter.user_id = _id + return { requestedFilter, filter diff --git a/workers/loc.api/sync/dao/helpers/get-insertable-array-objects-filter.js b/workers/loc.api/sync/dao/helpers/get-insertable-array-objects-filter.js index 58d4e945c..bb8818904 100644 --- a/workers/loc.api/sync/dao/helpers/get-insertable-array-objects-filter.js +++ b/workers/loc.api/sync/dao/helpers/get-insertable-array-objects-filter.js @@ -41,8 +41,7 @@ module.exports = ( dateFieldName, model, symbolFieldName, - timeframeFieldName, - additionalFilteringProps + timeframeFieldName } = {}, params = {} ) => { @@ -74,7 +73,6 @@ module.exports = ( _dateFieldName: dateFieldName, start, end, - ...additionalFilteringProps, ...symbFilter, ...timeframeFilter, ...fieldsFilters diff --git a/workers/loc.api/sync/dao/helpers/get-status-messages-filter.js b/workers/loc.api/sync/dao/helpers/get-status-messages-filter.js index 6f4e2927e..166eb14e0 100644 --- a/workers/loc.api/sync/dao/helpers/get-status-messages-filter.js +++ b/workers/loc.api/sync/dao/helpers/get-status-messages-filter.js @@ -6,8 +6,7 @@ const getSymbolFilter = require('./get-symbol-filter') module.exports = ( { name, - symbolFieldName, - additionalFilteringProps + symbolFieldName } = {}, params = {} ) => { @@ -24,7 +23,6 @@ module.exports = ( const filter = { ...reqFilter, _type: type, - ...additionalFilteringProps, ...symbFilter } From 0229dcb824e777e64ca9410f80700f74a3489ea0 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Thu, 16 Jul 2026 11:31:11 +0300 Subject: [PATCH 2/4] Add ledger filter getter --- .../sync/dao/helpers/get-ledgers-filter.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 workers/loc.api/sync/dao/helpers/get-ledgers-filter.js diff --git a/workers/loc.api/sync/dao/helpers/get-ledgers-filter.js b/workers/loc.api/sync/dao/helpers/get-ledgers-filter.js new file mode 100644 index 000000000..519d4cbaa --- /dev/null +++ b/workers/loc.api/sync/dao/helpers/get-ledgers-filter.js @@ -0,0 +1,27 @@ +'use strict' + +const TABLES_NAMES = require('../../schema/tables-names') + +module.exports = ( + methodColl, + args +) => { + if (methodColl.getModelField('NAME') !== TABLES_NAMES.LEDGERS) { + return {} + } + + const { auth, params } = args ?? {} + const filter = {} + + if (auth?.isSubAccount) { + filter._isBalanceRecalced = 1 + } + if (params?.wallet) { + filter.wallet = params.wallet + } + if (params?.category) { + filter._category = params.category + } + + return filter +} From 41e7acaaa60f6850cc45380c6d65e4e065339dae Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Thu, 16 Jul 2026 11:49:30 +0300 Subject: [PATCH 3/4] Use ledger filter getter for query builder --- .../find-in-coll-by/get-filter-params.js | 31 +++++++++---------- .../get-insertable-array-objects-filter.js | 9 +++--- .../dao/helpers/get-status-messages-filter.js | 4 +-- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/workers/loc.api/sync/dao/helpers/find-in-coll-by/get-filter-params.js b/workers/loc.api/sync/dao/helpers/find-in-coll-by/get-filter-params.js index fb7f27568..c3fb2ecd3 100644 --- a/workers/loc.api/sync/dao/helpers/find-in-coll-by/get-filter-params.js +++ b/workers/loc.api/sync/dao/helpers/find-in-coll-by/get-filter-params.js @@ -10,28 +10,35 @@ const getInsertableArrayObjectsFilter = require( const getStatusMessagesFilter = require( '../get-status-messages-filter' ) -const TABLES_NAMES = require('../../../schema/tables-names') +const getLedgersFilter = require( + '../get-ledgers-filter' +) const SUPPORTED_MODEL_FIELDS = require( '../../../schema/sync-schema/model/supported.model.fields' ) module.exports = (args, methodColl, opts) => { - const { auth, params } = { ...args } - const { filter: requestedFilter } = { ...params } - const { isPublic } = { ...opts } + const { auth, params } = args ?? {} + const { filter: requestedFilter } = params ?? {} + const { isPublic } = opts ?? {} const statusMessagesfilter = getStatusMessagesFilter( methodColl, - params + args ) const insertableArrayObjectsFilter = getInsertableArrayObjectsFilter( methodColl, - params + args + ) + const ledgersFilter = getLedgersFilter( + methodColl, + args ) const filter = { ...insertableArrayObjectsFilter, ...statusMessagesfilter, + ...ledgersFilter, ...methodColl[SUPPORTED_MODEL_FIELDS.ADDITIONAL_FILTERING_PROPS] } @@ -42,19 +49,11 @@ module.exports = (args, methodColl, opts) => { } } - const { _id, isSubAccount } = auth ?? {} - - if (!Number.isInteger(_id)) { + if (!Number.isInteger(auth?._id)) { throw new AuthError() } - if ( - methodColl.getModelField('NAME') === TABLES_NAMES.LEDGERS && - isSubAccount - ) { - filter._isBalanceRecalced = 1 - } - filter.user_id = _id + filter.user_id = auth._id return { requestedFilter, diff --git a/workers/loc.api/sync/dao/helpers/get-insertable-array-objects-filter.js b/workers/loc.api/sync/dao/helpers/get-insertable-array-objects-filter.js index bb8818904..0c55a2024 100644 --- a/workers/loc.api/sync/dao/helpers/get-insertable-array-objects-filter.js +++ b/workers/loc.api/sync/dao/helpers/get-insertable-array-objects-filter.js @@ -43,7 +43,7 @@ module.exports = ( symbolFieldName, timeframeFieldName } = {}, - params = {} + args ) => { if (!isInsertableArrObj(type)) { return {} @@ -55,17 +55,16 @@ module.exports = ( symbol, timeframe, filter: reqFilter = {} - } = { ...params } + } = args?.params ?? {} const symbFilter = getSymbolFilter(symbol, symbolFieldName) const timeframeFilter = getTimeframeFilter(timeframe, timeframeFieldName) const fieldsFilters = getFieldsFilters( [ 'isMarginFundingPayment', 'isAffiliateRebate', - 'isStakingPayments', - 'category' + 'isStakingPayments' ], - params, + args?.params, model ) const filter = { diff --git a/workers/loc.api/sync/dao/helpers/get-status-messages-filter.js b/workers/loc.api/sync/dao/helpers/get-status-messages-filter.js index 166eb14e0..e4c11f245 100644 --- a/workers/loc.api/sync/dao/helpers/get-status-messages-filter.js +++ b/workers/loc.api/sync/dao/helpers/get-status-messages-filter.js @@ -8,7 +8,7 @@ module.exports = ( name, symbolFieldName } = {}, - params = {} + args ) => { if (name !== TABLES_NAMES.STATUS_MESSAGES) { return {} @@ -18,7 +18,7 @@ module.exports = ( type, symbol, filter: reqFilter = {} - } = { ...params } + } = args?.params ?? {} const symbFilter = getSymbolFilter(symbol, symbolFieldName) const filter = { ...reqFilter, From 9af0f9967ab7706401942564eafa3eafc25a9937 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 17 Jul 2026 15:21:26 +0300 Subject: [PATCH 4/4] Add test case for getLedgers method filtered by wallet --- .../api-sync-mode-sqlite-test-cases.js | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/test-cases/api-sync-mode-sqlite-test-cases.js b/test/test-cases/api-sync-mode-sqlite-test-cases.js index d41baded9..fc7e55f7e 100644 --- a/test/test-cases/api-sync-mode-sqlite-test-cases.js +++ b/test/test-cases/api-sync-mode-sqlite-test-cases.js @@ -1458,6 +1458,37 @@ module.exports = ( }) }) + it('it should be successfully performed by the getLedgers method filtered by wallet', async function () { + this.timeout(5000) + + const res = await agent + .post(`${basePath}/json-rpc`) + .type('json') + .send({ + auth, + method: 'getLedgers', + params: { + wallet: 'exchange', + start: 0, + end, + limit: 2 + }, + id: 5 + }) + .expect('Content-Type', /json/) + .expect(200) + + assert.isObject(res.body) + assert.propertyVal(res.body, 'id', 5) + assert.isObject(res.body.result) + assert.isArray(res.body.result.res) + + for (const resItem of res.body.result.res) { + assert.isObject(resItem) + assert.deepEqual(resItem.wallet, 'exchange') + } + }) + it('it should be successfully performed by the getLedgers method, without params', async function () { this.timeout(5000)