From 9b896c21575026bfec18c0163dad7aba5035fb57 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Thu, 3 Sep 2026 22:25:36 +0100 Subject: [PATCH] Enhance data distribution and filtering by adding 'tags' to allowed filters and updating publish functionality This commit modifies the `distributeUpdate` function in `utils.js` to include the `_id` in the published object, improving data integrity during distribution. Additionally, it updates the allowed filters in the `products` and `clients` routes to include 'tags', enhancing the filtering capabilities for better data categorization and retrieval. --- src/routes/management/products.js | 3 ++- src/routes/sales/clients.js | 12 ++++++++++-- src/utils.js | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/routes/management/products.js b/src/routes/management/products.js index 33084ce..bee8b1a 100644 --- a/src/routes/management/products.js +++ b/src/routes/management/products.js @@ -16,6 +16,7 @@ const listAllowedFilters = [ 'price', 'margin', 'priceWithTax', + 'tags', 'createdAt', 'updatedAt', '_reference', @@ -33,7 +34,7 @@ const listAllowedSorters = [ 'priceWithTax', 'updatedAt', ]; -const propertiesAllowedFilters = []; +const propertiesAllowedFilters = ['tags']; import { listProductsRouteHandler, getProductRouteHandler, diff --git a/src/routes/sales/clients.js b/src/routes/sales/clients.js index 8799a3d..1ac7357 100644 --- a/src/routes/sales/clients.js +++ b/src/routes/sales/clients.js @@ -5,7 +5,15 @@ import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); -const listAllowedFilters = ['country', 'active', 'createdAt', 'updatedAt', 'name', '_reference']; +const listAllowedFilters = [ + 'country', + 'active', + 'tags', + 'createdAt', + 'updatedAt', + 'name', + '_reference', +]; const listAllowedSorters = [ 'name', 'country', @@ -16,7 +24,7 @@ const listAllowedSorters = [ 'updatedAt', '_id', ]; -const propertiesAllowedFilters = ['country', 'active', 'createdAt', 'updatedAt']; +const propertiesAllowedFilters = ['country', 'active', 'tags', 'createdAt', 'updatedAt']; import { listClientsRouteHandler, getClientRouteHandler, diff --git a/src/utils.js b/src/utils.js index c8b6c69..3b1a9f0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1404,7 +1404,7 @@ function filterDistributeKeys(value, keys = DISTRIBUTE_KEYS) { } async function distributeUpdate(value, id, type) { - await natsServer.publish(`${type}s.${id}.object`, value); + await natsServer.publish(`${type}s.${id}.object`, { ...value, _id: id }); } async function distributeStats(value, type) {