From f69c88926c6240f8911000304a586c5e0b80d2ad Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sat, 1 Aug 2026 18:25:59 +0100 Subject: [PATCH] Refactor allowedFilters in inventory and management routes to improve consistency and readability. Cleaned up whitespace and ensured all filters are properly formatted for better query handling across purchase orders, shipments, and filament SKUs. --- src/routes/inventory/purchaseorders.js | 58 +++++++++++++------------- src/routes/inventory/shipments.js | 42 +++++++++---------- src/routes/management/filamentskus.js | 32 +++++++------- src/routes/sales/salesorders.js | 25 +++++------ 4 files changed, 74 insertions(+), 83 deletions(-) diff --git a/src/routes/inventory/purchaseorders.js b/src/routes/inventory/purchaseorders.js index dcda94f..52c74e4 100644 --- a/src/routes/inventory/purchaseorders.js +++ b/src/routes/inventory/purchaseorders.js @@ -5,32 +5,32 @@ import { getFilter, convertPropertiesString } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'vendor', - 'state', - 'value', - 'vendor._id', - 'totalAmount', - 'totalAmountWithTax', - 'totalTaxAmount', - 'shippingAmount', - 'shippingAmountWithTax', - 'grandTotalAmount', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'vendor', + 'state', + 'value', + 'vendor._id', + 'totalAmount', + 'totalAmountWithTax', + 'totalTaxAmount', + 'shippingAmount', + 'shippingAmountWithTax', + 'grandTotalAmount', + 'createdAt', + 'updatedAt', + '_reference', +]; const propertiesAllowedFilters = [ - 'vendor', - 'state.type', - 'value', - 'vendor._id', - 'totalAmount', - 'totalAmountWithTax', - 'totalTaxAmount', - 'shippingAmount', - 'shippingAmountWithTax', - 'grandTotalAmount', - ]; + 'vendor', + 'state.type', + 'value', + 'vendor._id', + 'totalAmount', + 'totalAmountWithTax', + 'totalTaxAmount', + 'shippingAmount', + 'shippingAmountWithTax', + 'grandTotalAmount', +]; import { listPurchaseOrdersRouteHandler, getPurchaseOrderRouteHandler, @@ -46,14 +46,13 @@ import { cancelPurchaseOrderRouteHandler, searchPurchaseOrdersRouteHandler, getPurchaseOrderPropertyValuesRouteHandler, - - getPurchaseOrderNeighborsRouteHandler + getPurchaseOrderNeighborsRouteHandler, } from '../../services/inventory/purchaseorders.js'; // list of purchase orders router.get('/', isAuthenticated, (req, res) => { const { page, limit, property, search, sort, order } = req.query; - const filter = getFilter(req.query, listAllowedFilters); + const filter = getFilter(req.query, listAllowedFilters); listPurchaseOrdersRouteHandler(req, res, page, limit, property, filter, search, sort, order); }); @@ -62,7 +61,7 @@ router.get('/properties', isAuthenticated, (req, res) => { const filter = getFilter(req.query, propertiesAllowedFilters, false); var masterFilter = {}; if (req.query.masterFilter) { - masterFilter = getFilter(JSON.parse(req.query.masterFilter), allowedFilters, true); + masterFilter = getFilter(JSON.parse(req.query.masterFilter), propertiesAllowedFilters, true); } listPurchaseOrdersByPropertiesRouteHandler(req, res, properties, filter, masterFilter); }); @@ -76,7 +75,6 @@ router.get('/search', isAuthenticated, (req, res) => { searchPurchaseOrdersRouteHandler(req, res, search); }); - router.post('/', isAuthenticated, (req, res) => { newPurchaseOrderRouteHandler(req, res); }); diff --git a/src/routes/inventory/shipments.js b/src/routes/inventory/shipments.js index 596114e..3d3a276 100644 --- a/src/routes/inventory/shipments.js +++ b/src/routes/inventory/shipments.js @@ -5,24 +5,24 @@ import { getFilter, convertPropertiesString } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'orderType', - 'order', - 'state', - 'courierService', - 'order._id', - 'taxRate', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'orderType', + 'order', + 'state', + 'courierService', + 'order._id', + 'taxRate', + 'createdAt', + 'updatedAt', + '_reference', +]; const propertiesAllowedFilters = [ - 'orderType', - 'order', - 'state.type', - 'courierService', - 'order._id', - 'taxRate', - ]; + 'orderType', + 'order', + 'state.type', + 'courierService', + 'order._id', + 'taxRate', +]; import { listShipmentsRouteHandler, getShipmentRouteHandler, @@ -38,14 +38,13 @@ import { cancelShipmentRouteHandler, searchShipmentsRouteHandler, getShipmentPropertyValuesRouteHandler, - - getShipmentNeighborsRouteHandler + getShipmentNeighborsRouteHandler, } from '../../services/inventory/shipments.js'; // list of shipments router.get('/', isAuthenticated, (req, res) => { const { page, limit, property, search, sort, order } = req.query; - const filter = getFilter(req.query, listAllowedFilters); + const filter = getFilter(req.query, listAllowedFilters); listShipmentsRouteHandler(req, res, page, limit, property, filter, search, sort, order); }); @@ -54,7 +53,7 @@ router.get('/properties', isAuthenticated, (req, res) => { const filter = getFilter(req.query, propertiesAllowedFilters, false); var masterFilter = {}; if (req.query.masterFilter) { - masterFilter = getFilter(JSON.parse(req.query.masterFilter), allowedFilters, true); + masterFilter = getFilter(JSON.parse(req.query.masterFilter), propertiesAllowedFilters, true); } listShipmentsByPropertiesRouteHandler(req, res, properties, filter, masterFilter); }); @@ -68,7 +67,6 @@ router.get('/search', isAuthenticated, (req, res) => { searchShipmentsRouteHandler(req, res, search); }); - router.post('/', isAuthenticated, (req, res) => { newShipmentRouteHandler(req, res); }); diff --git a/src/routes/management/filamentskus.js b/src/routes/management/filamentskus.js index 965335c..32422a1 100644 --- a/src/routes/management/filamentskus.js +++ b/src/routes/management/filamentskus.js @@ -5,19 +5,19 @@ import { getFilter, convertPropertiesString } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - '_id', - 'barcode', - 'filament', - 'filament._id', - 'name', - 'color', - 'cost', - 'costWithTax', - 'createdAt', - 'updatedAt', - '_reference' - ]; -const propertiesAllowedFilters = ['filament', 'filament._id']; + '_id', + 'barcode', + 'filament', + 'filament._id', + 'name', + 'color', + 'cost', + 'costWithTax', + 'createdAt', + 'updatedAt', + '_reference', +]; +const propertiesAllowedFilters = ['filament', 'filament._id', 'diameter']; import { listFilamentSkusRouteHandler, getFilamentSkuRouteHandler, @@ -29,13 +29,12 @@ import { getFilamentSkuHistoryRouteHandler, searchFilamentSkusRouteHandler, getFilamentSkuPropertyValuesRouteHandler, - - getFilamentSkuNeighborsRouteHandler + getFilamentSkuNeighborsRouteHandler, } from '../../services/management/filamentskus.js'; router.get('/', isAuthenticated, (req, res) => { const { page, limit, property, search, sort, order } = req.query; - const filter = getFilter(req.query, listAllowedFilters); + const filter = getFilter(req.query, listAllowedFilters); listFilamentSkusRouteHandler(req, res, page, limit, property, filter, search, sort, order); }); @@ -58,7 +57,6 @@ router.get('/search', isAuthenticated, (req, res) => { searchFilamentSkusRouteHandler(req, res, search); }); - router.post('/', isAuthenticated, (req, res) => { newFilamentSkuRouteHandler(req, res); }); diff --git a/src/routes/sales/salesorders.js b/src/routes/sales/salesorders.js index 2032170..23772bf 100644 --- a/src/routes/sales/salesorders.js +++ b/src/routes/sales/salesorders.js @@ -5,14 +5,14 @@ import { getFilter, convertPropertiesString } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'client', - 'state', - 'value', - 'client._id', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'client', + 'state', + 'value', + 'client._id', + 'createdAt', + 'updatedAt', + '_reference', +]; const propertiesAllowedFilters = ['client', 'state.type', 'value', 'client._id']; import { listSalesOrdersRouteHandler, @@ -29,14 +29,13 @@ import { cancelSalesOrderRouteHandler, searchSalesOrdersRouteHandler, getSalesOrderPropertyValuesRouteHandler, - - getSalesOrderNeighborsRouteHandler + getSalesOrderNeighborsRouteHandler, } from '../../services/sales/salesorders.js'; // list of sales orders router.get('/', isAuthenticated, (req, res) => { const { page, limit, property, search, sort, order } = req.query; - const filter = getFilter(req.query, listAllowedFilters); + const filter = getFilter(req.query, listAllowedFilters); listSalesOrdersRouteHandler(req, res, page, limit, property, filter, search, sort, order); }); @@ -45,7 +44,7 @@ router.get('/properties', isAuthenticated, (req, res) => { const filter = getFilter(req.query, propertiesAllowedFilters, false); var masterFilter = {}; if (req.query.masterFilter) { - masterFilter = getFilter(JSON.parse(req.query.masterFilter), allowedFilters, true); + masterFilter = getFilter(JSON.parse(req.query.masterFilter), propertiesAllowedFilters, true); } listSalesOrdersByPropertiesRouteHandler(req, res, properties, filter, masterFilter); }); @@ -59,7 +58,6 @@ router.get('/search', isAuthenticated, (req, res) => { searchSalesOrdersRouteHandler(req, res, search); }); - router.post('/', isAuthenticated, (req, res) => { newSalesOrderRouteHandler(req, res); }); @@ -110,4 +108,3 @@ router.post('/:id/cancel', isAuthenticated, async (req, res) => { }); export default router; -