Enhance data distribution and filtering by adding 'tags' to allowed filters and updating publish functionality
All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good

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.
This commit is contained in:
Tom Butcher 2026-09-03 22:25:36 +01:00
parent efcf1389a5
commit 9b896c2157
3 changed files with 13 additions and 4 deletions

View File

@ -16,6 +16,7 @@ const listAllowedFilters = [
'price', 'price',
'margin', 'margin',
'priceWithTax', 'priceWithTax',
'tags',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference', '_reference',
@ -33,7 +34,7 @@ const listAllowedSorters = [
'priceWithTax', 'priceWithTax',
'updatedAt', 'updatedAt',
]; ];
const propertiesAllowedFilters = []; const propertiesAllowedFilters = ['tags'];
import { import {
listProductsRouteHandler, listProductsRouteHandler,
getProductRouteHandler, getProductRouteHandler,

View File

@ -5,7 +5,15 @@ import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = ['country', 'active', 'createdAt', 'updatedAt', 'name', '_reference']; const listAllowedFilters = [
'country',
'active',
'tags',
'createdAt',
'updatedAt',
'name',
'_reference',
];
const listAllowedSorters = [ const listAllowedSorters = [
'name', 'name',
'country', 'country',
@ -16,7 +24,7 @@ const listAllowedSorters = [
'updatedAt', 'updatedAt',
'_id', '_id',
]; ];
const propertiesAllowedFilters = ['country', 'active', 'createdAt', 'updatedAt']; const propertiesAllowedFilters = ['country', 'active', 'tags', 'createdAt', 'updatedAt'];
import { import {
listClientsRouteHandler, listClientsRouteHandler,
getClientRouteHandler, getClientRouteHandler,

View File

@ -1404,7 +1404,7 @@ function filterDistributeKeys(value, keys = DISTRIBUTE_KEYS) {
} }
async function distributeUpdate(value, id, type) { 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) { async function distributeStats(value, type) {