diff --git a/src/routes/finance/invoices.js b/src/routes/finance/invoices.js index 511a25f..fe0a99e 100644 --- a/src/routes/finance/invoices.js +++ b/src/routes/finance/invoices.js @@ -1,22 +1,23 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'vendor', - 'client', - 'state', - 'vendor._id', - 'client._id', - 'order', - 'order._id', - 'orderType', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'vendor', + 'client', + 'state', + 'vendor._id', + 'client._id', + 'order', + 'order._id', + 'orderType', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['createdAt', 'state', 'updatedAt', 'invoiceDate', 'dueDate']; const propertiesAllowedFilters = [ 'vendor', 'client', @@ -50,7 +51,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listInvoicesRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listInvoicesRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -90,7 +91,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getInvoiceNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getInvoiceNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/finance/payments.js b/src/routes/finance/payments.js index 4158d5d..0611e37 100644 --- a/src/routes/finance/payments.js +++ b/src/routes/finance/payments.js @@ -1,21 +1,22 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'vendor', - 'client', - 'state', - 'vendor._id', - 'client._id', - 'invoice', - 'invoice._id', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'vendor', + 'client', + 'state', + 'vendor._id', + 'client._id', + 'invoice', + 'invoice._id', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['createdAt', 'state', 'updatedAt', 'paymentDate']; const propertiesAllowedFilters = [ 'vendor', 'client', @@ -50,7 +51,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listPaymentsRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listPaymentsRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -90,7 +91,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getPaymentNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getPaymentNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/finance/taxrecords.js b/src/routes/finance/taxrecords.js index 2728bf8..81ea634 100644 --- a/src/routes/finance/taxrecords.js +++ b/src/routes/finance/taxrecords.js @@ -1,18 +1,21 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'taxRate', - 'transactionType', - 'transaction', - 'transactionDate', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'taxRate', + 'taxRate._id', + 'transactionType', + 'transaction', + 'transaction._id', + 'transactionDate', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['transactionDate', 'amount', 'taxAmount', 'createdAt', '_id', 'updatedAt']; const propertiesAllowedFilters = ['taxRate', 'transactionType', 'transaction']; import { listTaxRecordsRouteHandler, @@ -33,7 +36,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listTaxRecordsRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listTaxRecordsRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -73,7 +76,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getTaxRecordNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getTaxRecordNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/inventory/filamentstocks.js b/src/routes/inventory/filamentstocks.js index 8cfefe5..ca928d0 100644 --- a/src/routes/inventory/filamentstocks.js +++ b/src/routes/inventory/filamentstocks.js @@ -1,23 +1,24 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'filament', - 'filament._id', - 'filamentSku', - 'state', - 'startingWeight', - 'currentWeight', - 'filamentSku._id', - 'stockLocation', - 'stockLocation._id', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'filament', + 'filament._id', + 'filamentSku', + 'filamentSku._id', + 'state', + 'startingWeight', + 'currentWeight', + 'stockLocation', + 'stockLocation._id', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['createdAt', 'updatedAt', 'filament', 'filamentSku', 'state']; const propertiesAllowedFilters = [ 'filament', 'filament._id', @@ -45,7 +46,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listFilamentStocksRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listFilamentStocksRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -85,7 +86,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getFilamentStockNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getFilamentStockNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/inventory/orderitems.js b/src/routes/inventory/orderitems.js index 258d6a0..e50a786 100644 --- a/src/routes/inventory/orderitems.js +++ b/src/routes/inventory/orderitems.js @@ -1,6 +1,6 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); @@ -19,6 +19,7 @@ const listAllowedFilters = [ 'updatedAt', '_reference', ]; +const listAllowedSorters = ['createdAt', 'updatedAt', 'itemAmount', 'quantity', 'state', 'name']; const propertiesAllowedFilters = [ 'name', 'itemType', @@ -49,7 +50,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listOrderItemsRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listOrderItemsRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -88,7 +89,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getOrderItemNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getOrderItemNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/inventory/partstocks.js b/src/routes/inventory/partstocks.js index 47b0703..a006667 100644 --- a/src/routes/inventory/partstocks.js +++ b/src/routes/inventory/partstocks.js @@ -1,21 +1,22 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'partSku', - 'state', - 'startingQuantity', - 'currentQuantity', - 'partSku._id', - 'stockLocation', - 'stockLocation._id', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'partSku', + 'partSku._id', + 'state', + 'startingQuantity', + 'currentQuantity', + 'stockLocation', + 'stockLocation._id', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['partSku', 'startingQuantity', 'currentQuantity', 'state', 'createdAt', 'updatedAt']; const propertiesAllowedFilters = ['part', 'state.type']; import { listPartStocksRouteHandler, @@ -37,7 +38,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listPartStocksRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listPartStocksRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -77,7 +78,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getPartStockNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getPartStockNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/inventory/productstocks.js b/src/routes/inventory/productstocks.js index 4be28d0..e14a2fc 100644 --- a/src/routes/inventory/productstocks.js +++ b/src/routes/inventory/productstocks.js @@ -1,20 +1,21 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'productSku', - 'state', - 'currentQuantity', - 'productSku._id', - 'stockLocation', - 'stockLocation._id', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'productSku', + 'productSku._id', + 'state', + 'currentQuantity', + 'stockLocation', + 'stockLocation._id', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['productSku', 'currentQuantity', 'state', 'createdAt', 'updatedAt']; const propertiesAllowedFilters = ['productSku', 'state.type']; import { listProductStocksRouteHandler, @@ -36,7 +37,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listProductStocksRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listProductStocksRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -74,7 +75,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getProductStockNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getProductStockNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/inventory/purchaseorders.js b/src/routes/inventory/purchaseorders.js index e0216e9..26dd5d2 100644 --- a/src/routes/inventory/purchaseorders.js +++ b/src/routes/inventory/purchaseorders.js @@ -1,14 +1,14 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ 'vendor', + 'vendor._id', 'state', 'value', - 'vendor._id', 'totalAmount', 'totalAmountWithTax', 'totalTaxAmount', @@ -19,6 +19,17 @@ const listAllowedFilters = [ 'updatedAt', '_reference', ]; +const listAllowedSorters = [ + 'createdAt', + 'state', + 'updatedAt', + 'totalAmount', + 'totalAmountWithTax', + 'totalTaxAmount', + 'shippingAmount', + 'shippingAmountWithTax', + 'grandTotalAmount', +]; const propertiesAllowedFilters = [ 'vendor', 'state.type', @@ -53,7 +64,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listPurchaseOrdersRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listPurchaseOrdersRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -92,7 +103,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getPurchaseOrderNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getPurchaseOrderNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/inventory/shipments.js b/src/routes/inventory/shipments.js index 6d5deae..b8ed463 100644 --- a/src/routes/inventory/shipments.js +++ b/src/routes/inventory/shipments.js @@ -1,20 +1,23 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ 'orderType', 'order', + 'order._id', 'state', 'courierService', - 'order._id', + 'courierService._id', 'taxRate', + 'taxRate._id', 'createdAt', 'updatedAt', '_reference', ]; +const listAllowedSorters = ['createdAt', 'state', 'updatedAt', 'shippedAt', 'expectedAt', 'deliveredAt']; const propertiesAllowedFilters = [ 'orderType', 'order', @@ -45,7 +48,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listShipmentsRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listShipmentsRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -84,7 +87,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getShipmentNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getShipmentNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/inventory/stockaudits.js b/src/routes/inventory/stockaudits.js index b1c1a25..9b5b855 100644 --- a/src/routes/inventory/stockaudits.js +++ b/src/routes/inventory/stockaudits.js @@ -1,6 +1,6 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { parseFilter, getFilter } from '../../utils.js'; +import { parseFilter, getFilter, getSort } from '../../utils.js'; const router = express.Router(); import { @@ -16,14 +16,15 @@ import { } from '../../services/inventory/stockaudits.js'; const listAllowedFilters = [ - 'status', - 'type', - 'createdBy', - 'state', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'status', + 'type', + 'createdBy', + 'state', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['createdAt', 'updatedAt', 'state']; // List stock audits router.get('/', isAuthenticated, async (req, res) => { @@ -66,7 +67,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getStockAuditNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getStockAuditNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); // Get specific stock audit diff --git a/src/routes/inventory/stockevents.js b/src/routes/inventory/stockevents.js index e7c4bc0..a2df923 100644 --- a/src/routes/inventory/stockevents.js +++ b/src/routes/inventory/stockevents.js @@ -1,16 +1,11 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); -const listAllowedFilters = [ - 'owner._id', - 'parent._id', - 'createdAt', - 'updatedAt', - '_reference' - ]; +const listAllowedFilters = ['owner._id', 'parent._id', 'createdAt', 'updatedAt', '_reference']; +const listAllowedSorters = ['createdAt', 'updatedAt']; const propertiesAllowedFilters = ['owner._id', 'parent._id']; import { listStockEventsRouteHandler, @@ -32,7 +27,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listStockEventsRouteHandler(req, res, page, limit, filter, sort, order); + listStockEventsRouteHandler(req, res, page, limit, filter, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -72,7 +67,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getStockEventNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getStockEventNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/inventory/stocklocations.js b/src/routes/inventory/stocklocations.js index f7640ae..1cf90ff 100644 --- a/src/routes/inventory/stocklocations.js +++ b/src/routes/inventory/stocklocations.js @@ -1,10 +1,11 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); -const listAllowedFilters = ['name','createdAt','updatedAt','_reference']; +const listAllowedFilters = ['name', 'createdAt', 'updatedAt', '_reference']; +const listAllowedSorters = ['name', 'createdAt', 'updatedAt']; const propertiesAllowedFilters = ['name']; import { listStockLocationsRouteHandler, @@ -25,7 +26,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listStockLocationsRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listStockLocationsRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -63,7 +64,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getStockLocationNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getStockLocationNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/inventory/stocktransfers.js b/src/routes/inventory/stocktransfers.js index b400f90..440b29a 100644 --- a/src/routes/inventory/stocktransfers.js +++ b/src/routes/inventory/stocktransfers.js @@ -1,18 +1,19 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'state', - 'state.type', - 'postedAt', - 'name', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'state', + 'state.type', + 'postedAt', + 'name', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['name', 'createdAt', 'postedAt', 'state', 'updatedAt']; const propertiesAllowedFilters = ['state.type']; import { listStockTransfersRouteHandler, @@ -34,7 +35,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listStockTransfersRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listStockTransfersRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -72,7 +73,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getStockTransferNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getStockTransferNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/apppasswords.js b/src/routes/management/apppasswords.js index 1434e88..09f49eb 100644 --- a/src/routes/management/apppasswords.js +++ b/src/routes/management/apppasswords.js @@ -1,19 +1,20 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - '_id', - 'name', - 'user', - 'active', - 'user._id', - 'createdAt', - 'updatedAt', - '_reference' - ]; + '_id', + 'name', + 'user', + 'user._id', + 'active', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['name', 'user', 'active', 'createdAt', 'updatedAt']; const propertiesAllowedFilters = ['name', 'user', 'active']; import { listAppPasswordsRouteHandler, @@ -34,7 +35,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listAppPasswordsRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listAppPasswordsRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -73,7 +74,7 @@ router.post('/:id/regenerateSecret', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getAppPasswordNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getAppPasswordNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/auditlogs.js b/src/routes/management/auditlogs.js index 584e2ae..20001fc 100644 --- a/src/routes/management/auditlogs.js +++ b/src/routes/management/auditlogs.js @@ -7,37 +7,19 @@ import { getAuditLogHistoryRouteHandler, searchAuditLogsRouteHandler, } from '../../services/management/auditlogs.js'; -import { parseFilter } from '../../utils.js'; +import { getFilter, getSort } from '../../utils.js'; const router = express.Router(); -// List note types +const listAllowedFilters = ['parent._id', 'owner._id', 'operation', 'createdAt', 'updatedAt', '_reference']; +const listAllowedSorters = ['createdAt', 'updatedAt']; + router.get('/', isAuthenticated, async (req, res) => { const { page, limit, sort, order } = req.query; - - const allowedFilters = [ - 'parent._id', - 'owner._id', - 'operation', - 'createdAt', - 'updatedAt', - '_reference' - ]; - - var filter = {}; - - for (const [key, value] of Object.entries(req.query)) { - for (var i = 0; i < allowedFilters.length; i++) { - if (key == allowedFilters[i]) { - const parsedFilter = await parseFilter(key, value); - filter = { ...filter, ...parsedFilter }; - } - } - } - listAuditLogsRouteHandler(req, res, page, limit, filter, sort, order); + const filter = await getFilter(req.query, listAllowedFilters); + listAuditLogsRouteHandler(req, res, page, limit, filter, getSort(sort, listAllowedSorters), order); }); -// get audit log stats router.get('/search', isAuthenticated, async (req, res) => { const { search } = req.query; searchAuditLogsRouteHandler(req, res, search); @@ -47,16 +29,10 @@ router.get('/stats', isAuthenticated, async (req, res) => { getAuditLogStatsRouteHandler(req, res); }); -// get audit log history router.get('/history', isAuthenticated, async (req, res) => { getAuditLogHistoryRouteHandler(req, res); }); -/** - * @route GET /api/auditlogs/:id - * @desc Get a single audit log by ID - * @access Private - */ router.get('/:id', async (req, res) => { await getAuditLogRouteHandler(req, res); }); diff --git a/src/routes/management/courier.js b/src/routes/management/courier.js index 33cf884..e7b313f 100644 --- a/src/routes/management/courier.js +++ b/src/routes/management/courier.js @@ -1,20 +1,21 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'name', - 'website', - 'email', - 'phone', - 'contact', - 'country', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'name', + 'website', + 'email', + 'phone', + 'contact', + 'country', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['name', 'country', 'email', 'createdAt', '_id', 'updatedAt']; const propertiesAllowedFilters = ['name', 'website', 'email', 'phone', 'contact', 'country']; import { listCouriersRouteHandler, @@ -35,7 +36,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listCouriersRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listCouriersRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -75,7 +76,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getCourierNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getCourierNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/courierservice.js b/src/routes/management/courierservice.js index 434ca79..d0e2bf5 100644 --- a/src/routes/management/courierservice.js +++ b/src/routes/management/courierservice.js @@ -1,23 +1,35 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - '_id', - 'courier', - 'courier._id', - 'name', - 'active', - 'tracked', - 'deliveryTime', - 'cost', - 'costWithTax', - 'createdAt', - 'updatedAt', - '_reference' - ]; + '_id', + 'courier', + 'courier._id', + 'name', + 'active', + 'tracked', + 'deliveryTime', + 'cost', + 'costWithTax', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = [ + 'name', + 'courier', + 'active', + 'tracked', + 'cost', + 'costWithTax', + 'estimatedDeliveryTime', + 'createdAt', + '_id', + 'updatedAt', +]; const propertiesAllowedFilters = [ '_id', 'courier', @@ -48,7 +60,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listCourierServicesRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listCourierServicesRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -88,7 +100,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getCourierServiceNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getCourierServiceNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/documentjobs.js b/src/routes/management/documentjobs.js index 2ac6d13..9b8f171 100644 --- a/src/routes/management/documentjobs.js +++ b/src/routes/management/documentjobs.js @@ -1,18 +1,19 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'name', - 'width', - 'height', - 'state', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'name', + 'width', + 'height', + 'state', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['name', 'state', 'createdAt', 'updatedAt']; const propertiesAllowedFilters = []; import { listDocumentJobsRouteHandler, @@ -33,7 +34,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listDocumentJobsRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listDocumentJobsRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -73,7 +74,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getDocumentJobNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getDocumentJobNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/documentprinters.js b/src/routes/management/documentprinters.js index 3d84266..8371da2 100644 --- a/src/routes/management/documentprinters.js +++ b/src/routes/management/documentprinters.js @@ -1,19 +1,20 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'name', - 'tags', - 'active', - 'isGlobal', - 'state', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'name', + 'tags', + 'active', + 'isGlobal', + 'state', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['name', 'documentSize', 'connectedAt', 'updatedAt', 'state', 'createdAt']; const propertiesAllowedFilters = ['tags']; import { listDocumentPrintersRouteHandler, @@ -34,7 +35,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listDocumentPrintersRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listDocumentPrintersRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -74,7 +75,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getDocumentPrinterNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getDocumentPrinterNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/documentsizes.js b/src/routes/management/documentsizes.js index 6a77ea9..cf5b5b9 100644 --- a/src/routes/management/documentsizes.js +++ b/src/routes/management/documentsizes.js @@ -1,17 +1,11 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); -const listAllowedFilters = [ - 'name', - 'width', - 'height', - 'createdAt', - 'updatedAt', - '_reference' - ]; +const listAllowedFilters = ['name', 'width', 'height', 'createdAt', 'updatedAt', '_reference']; +const listAllowedSorters = ['name', 'width', 'height', 'infiniteHeight', 'createdAt', 'updatedAt']; const propertiesAllowedFilters = []; import { listDocumentSizesRouteHandler, @@ -32,7 +26,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listDocumentSizesRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listDocumentSizesRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -72,7 +66,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getDocumentSizeNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getDocumentSizeNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/documenttemplates.js b/src/routes/management/documenttemplates.js index 6448f1c..3eb9055 100644 --- a/src/routes/management/documenttemplates.js +++ b/src/routes/management/documenttemplates.js @@ -1,19 +1,33 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'name', - 'tags', - 'active', - 'global', - 'objectType', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'name', + 'tags', + 'active', + 'global', + 'parent', + 'parent._id', + 'documentSize', + 'documentSize._id', + 'objectType', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = [ + 'name', + 'parent', + 'documentSize', + 'createdAt', + 'updatedAt', + 'active', + 'global', + 'objectType', +]; const propertiesAllowedFilters = ['documentSize', 'tags']; import { listDocumentTemplatesRouteHandler, @@ -33,7 +47,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listDocumentTemplatesRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listDocumentTemplatesRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -73,7 +87,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getDocumentTemplateNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getDocumentTemplateNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/filaments.js b/src/routes/management/filaments.js index b32a75e..077f286 100644 --- a/src/routes/management/filaments.js +++ b/src/routes/management/filaments.js @@ -1,20 +1,29 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { convertPropertiesString, getFilter, parseFilter } from '../../utils.js'; +import { convertPropertiesString, getFilter, parseFilter, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - '_id', - 'material', - 'material._id', - 'diameter', - 'name', - 'cost', - 'createdAt', - 'updatedAt', - '_reference' - ]; + '_id', + 'material', + 'material._id', + 'diameter', + 'name', + 'cost', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = [ + 'name', + 'createdAt', + 'vendor', + 'material', + 'cost', + 'costWithTax', + 'updatedAt', +]; const propertiesAllowedFilters = ['diameter', 'material']; import { listFilamentsRouteHandler, @@ -47,7 +56,7 @@ router.get('/', isAuthenticated, async (req, res) => { } } - listFilamentsRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listFilamentsRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -87,7 +96,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getFilamentNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getFilamentNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/filamentskus.js b/src/routes/management/filamentskus.js index b5fe72a..b9a981c 100644 --- a/src/routes/management/filamentskus.js +++ b/src/routes/management/filamentskus.js @@ -1,6 +1,6 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); @@ -17,6 +17,16 @@ const listAllowedFilters = [ 'updatedAt', '_reference', ]; +const listAllowedSorters = [ + 'barcode', + 'filament', + 'name', + 'color', + 'cost', + 'costWithTax', + 'createdAt', + 'updatedAt', +]; const propertiesAllowedFilters = ['filament', 'filament._id', 'diameter']; import { listFilamentSkusRouteHandler, @@ -35,7 +45,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listFilamentSkusRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listFilamentSkusRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -72,7 +82,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getFilamentSkuNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getFilamentSkuNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/files.js b/src/routes/management/files.js index b9c9a9f..c6c039c 100644 --- a/src/routes/management/files.js +++ b/src/routes/management/files.js @@ -1,19 +1,20 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - '_id', - 'name', - 'type', - 'size', - 'extension', - 'createdAt', - 'updatedAt', - '_reference' - ]; + '_id', + 'name', + 'type', + 'size', + 'extension', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['name', 'type', 'size', 'createdAt', 'temp', 'updatedAt']; const propertiesAllowedFilters = ['type', 'extension']; import { listFilesRouteHandler, @@ -37,7 +38,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listFilesRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listFilesRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -81,7 +82,7 @@ router.delete('/:id/flush', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getFileNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getFileNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/hosts.js b/src/routes/management/hosts.js index 9358e21..78a7da7 100644 --- a/src/routes/management/hosts.js +++ b/src/routes/management/hosts.js @@ -1,18 +1,20 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - '_id', - 'name', - 'tags', - 'state', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'name', + '_id', + 'state', + 'tags', + 'connectedAt', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['name', 'state', 'connectedAt', 'createdAt', 'updatedAt']; const propertiesAllowedFilters = ['tags']; import { listHostsRouteHandler, @@ -32,7 +34,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listHostsRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listHostsRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -72,7 +74,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getHostNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getHostNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/materials.js b/src/routes/management/materials.js index 4616f7c..5ea85bc 100644 --- a/src/routes/management/materials.js +++ b/src/routes/management/materials.js @@ -1,17 +1,11 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { convertPropertiesString, getFilter, parseFilter } from '../../utils.js'; +import { convertPropertiesString, getFilter, parseFilter, getSort } from '../../utils.js'; const router = express.Router(); -const listAllowedFilters = [ - '_id', - 'name', - 'tags', - 'createdAt', - 'updatedAt', - '_reference' - ]; +const listAllowedFilters = ['_id', 'name', 'tags', 'createdAt', 'updatedAt', '_reference']; +const listAllowedSorters = ['name', 'createdAt', 'updatedAt', '_id']; const propertiesAllowedFilters = ['name', 'tags']; import { listMaterialsRouteHandler, @@ -40,7 +34,7 @@ router.get('/', isAuthenticated, async (req, res) => { } } - listMaterialsRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listMaterialsRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -80,7 +74,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getMaterialNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getMaterialNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/notetypes.js b/src/routes/management/notetypes.js index 7cf2e27..d6b99c6 100644 --- a/src/routes/management/notetypes.js +++ b/src/routes/management/notetypes.js @@ -1,18 +1,19 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - '_id', - 'name', - 'active', - 'color', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'name', + '_id', + 'color', + 'active', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['name', 'color', 'active', 'createdAt', 'updatedAt']; const propertiesAllowedFilters = ['active', 'color']; import { listNoteTypesRouteHandler, @@ -33,7 +34,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listNoteTypesRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listNoteTypesRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -73,7 +74,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getNoteTypeNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getNoteTypeNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/parts.js b/src/routes/management/parts.js index c55e9aa..f82341e 100644 --- a/src/routes/management/parts.js +++ b/src/routes/management/parts.js @@ -1,17 +1,21 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); -const listAllowedFilters = [ - 'product._id', - '_id', - 'name', - 'createdAt', - 'updatedAt', - '_reference' - ]; +const listAllowedFilters = ['product._id', '_id', 'name', 'createdAt', 'updatedAt', '_reference']; +const listAllowedSorters = [ + 'name', + 'priceMode', + 'cost', + 'costWithTax', + 'price', + 'priceWithTax', + 'createdAt', + 'updatedAt', + '_id', +]; const propertiesAllowedFilters = ['product._id']; import { listPartsRouteHandler, @@ -32,7 +36,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listPartsRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listPartsRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -72,7 +76,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getPartNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getPartNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/partskus.js b/src/routes/management/partskus.js index 2dfc7f8..63e9c32 100644 --- a/src/routes/management/partskus.js +++ b/src/routes/management/partskus.js @@ -1,21 +1,32 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - '_id', - 'barcode', - 'part', - 'part._id', - 'name', - 'cost', - 'price', - 'createdAt', - 'updatedAt', - '_reference' - ]; + '_id', + 'barcode', + 'part', + 'part._id', + 'name', + 'cost', + 'price', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = [ + 'barcode', + 'part', + 'name', + 'cost', + 'costWithTax', + 'price', + 'priceWithTax', + 'createdAt', + 'updatedAt', +]; const propertiesAllowedFilters = ['part', 'part._id']; import { listPartSkusRouteHandler, @@ -35,7 +46,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listPartSkusRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listPartSkusRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -73,7 +84,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getPartSkuNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getPartSkuNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/productcategories.js b/src/routes/management/productcategories.js index 0fcc505..5001bda 100644 --- a/src/routes/management/productcategories.js +++ b/src/routes/management/productcategories.js @@ -1,6 +1,6 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { convertPropertiesString, getFilter } from '../../utils.js'; +import { convertPropertiesString, getFilter, getSort } from '../../utils.js'; import { deleteProductCategoryRouteHandler, editProductCategoryRouteHandler, @@ -18,13 +18,14 @@ import { const router = express.Router(); -const listAllowedFilters = ['_id','name','createdAt','updatedAt','_reference']; +const listAllowedFilters = ['_id', 'name', 'createdAt', 'updatedAt', '_reference']; +const listAllowedSorters = ['name', 'createdAt', 'updatedAt', '_id']; const propertiesAllowedFilters = ['name']; router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listProductCategoriesRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listProductCategoriesRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -62,7 +63,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getProductCategoryNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getProductCategoryNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/products.js b/src/routes/management/products.js index 8c830cf..490b9c4 100644 --- a/src/routes/management/products.js +++ b/src/routes/management/products.js @@ -1,19 +1,31 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - '_id', - 'name', - 'globalPrice', - 'productCategory', - 'productCategory._id', - 'createdAt', - 'updatedAt', - '_reference' - ]; + '_id', + 'name', + 'globalPrice', + 'productCategory', + 'productCategory._id', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = [ + 'name', + 'productCategory', + 'createdAt', + 'type', + 'vendor', + 'cost', + 'costWithTax', + 'price', + 'priceWithTax', + 'updatedAt', +]; const propertiesAllowedFilters = []; import { listProductsRouteHandler, @@ -34,7 +46,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listProductsRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listProductsRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -74,7 +86,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getProductNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getProductNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/productskus.js b/src/routes/management/productskus.js index e5cb3b0..2a1abba 100644 --- a/src/routes/management/productskus.js +++ b/src/routes/management/productskus.js @@ -1,21 +1,32 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - '_id', - 'barcode', - 'product', - 'product._id', - 'name', - 'cost', - 'price', - 'createdAt', - 'updatedAt', - '_reference' - ]; + '_id', + 'barcode', + 'product', + 'product._id', + 'name', + 'cost', + 'price', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = [ + 'barcode', + 'product', + 'name', + 'cost', + 'costWithTax', + 'price', + 'priceWithTax', + 'createdAt', + 'updatedAt', +]; const propertiesAllowedFilters = ['product', 'product._id']; import { listProductSkusRouteHandler, @@ -35,7 +46,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listProductSkusRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listProductSkusRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -73,7 +84,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getProductSkuNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getProductSkuNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/taxrates.js b/src/routes/management/taxrates.js index f247f20..0607077 100644 --- a/src/routes/management/taxrates.js +++ b/src/routes/management/taxrates.js @@ -1,19 +1,29 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'name', - 'rate', - 'rateType', - 'active', - 'country', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'name', + 'rate', + 'rateType', + 'active', + 'country', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = [ + 'name', + 'rate', + 'rateType', + 'active', + 'country', + 'createdAt', + '_id', + 'updatedAt', +]; const propertiesAllowedFilters = ['rateType', 'country', 'active']; import { listTaxRatesRouteHandler, @@ -34,7 +44,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listTaxRatesRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listTaxRatesRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -74,7 +84,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getTaxRateNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getTaxRateNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/users.js b/src/routes/management/users.js index baeb3f2..41125d0 100644 --- a/src/routes/management/users.js +++ b/src/routes/management/users.js @@ -1,19 +1,20 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { convertPropertiesString, getFilter } from '../../utils.js'; +import { convertPropertiesString, getFilter, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'name', - 'username', - 'firstName', - 'lastName', - 'email', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'name', + 'username', + 'firstName', + 'lastName', + 'email', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['name', 'email', 'role', 'createdAt', '_id', 'updatedAt']; const propertiesAllowedFilters = []; import { listUsersRouteHandler, @@ -33,7 +34,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listUsersRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listUsersRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -69,7 +70,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getUserNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getUserNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/management/vendors.js b/src/routes/management/vendors.js index 9162d79..9e1adf0 100644 --- a/src/routes/management/vendors.js +++ b/src/routes/management/vendors.js @@ -1,17 +1,19 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); -const listAllowedFilters = [ - 'country', - 'active', - 'createdAt', - 'updatedAt', - 'name', - '_reference' - ]; +const listAllowedFilters = ['country', 'active', 'createdAt', 'updatedAt', 'name', '_reference']; +const listAllowedSorters = [ + 'name', + 'country', + 'email', + 'active', + 'createdAt', + 'updatedAt', + '_id', +]; const propertiesAllowedFilters = ['country', 'active', 'createdAt', 'updatedAt']; import { listVendorsRouteHandler, @@ -32,7 +34,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listVendorsRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listVendorsRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -72,7 +74,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getVendorNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getVendorNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/misc/notes.js b/src/routes/misc/notes.js index fa388ac..1117341 100644 --- a/src/routes/misc/notes.js +++ b/src/routes/misc/notes.js @@ -13,23 +13,31 @@ import { getNoteNeighborsRouteHandler } from '../../services/misc/notes.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'parent._id', - 'createdAt', - 'updatedAt', - '_reference' - ]; + '_id', + 'user', + 'user._id', + 'parentType', + 'parent', + 'parent._id', + 'noteType', + 'noteType._id', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['createdAt', 'updatedAt', 'parentType', 'noteType']; const propertiesAllowedFilters = ['parent']; // list of notes router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listNotesRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listNotesRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -65,7 +73,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getNoteNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getNoteNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/production/filamentprofiles.js b/src/routes/production/filamentprofiles.js index c1bf29e..8fb6a8c 100644 --- a/src/routes/production/filamentprofiles.js +++ b/src/routes/production/filamentprofiles.js @@ -1,6 +1,6 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { convertPropertiesString, getFilter } from '../../utils.js'; +import { convertPropertiesString, getFilter, getSort } from '../../utils.js'; import { deleteFilamentProfileRouteHandler, editFilamentProfileRouteHandler, @@ -16,13 +16,14 @@ import { const router = express.Router(); -const listAllowedFilters = ['_id','name','createdAt','updatedAt','_reference']; +const listAllowedFilters = ['_id', 'name', 'createdAt', 'updatedAt', '_reference']; +const listAllowedSorters = ['name', 'createdAt', 'updatedAt']; const propertiesAllowedFilters = ['name']; router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listFilamentProfilesRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listFilamentProfilesRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -51,7 +52,7 @@ router.post('/', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getFilamentProfileNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getFilamentProfileNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/production/gcodefiles.js b/src/routes/production/gcodefiles.js index 69912a7..cfff7fb 100644 --- a/src/routes/production/gcodefiles.js +++ b/src/routes/production/gcodefiles.js @@ -4,16 +4,17 @@ import { isAuthenticated } from '../../keycloak.js'; const router = express.Router(); const listAllowedFilters = [ - '_id', - 'name', - 'filament', - 'filament._id', - 'filamentSku', - 'filamentSku._id', - 'createdAt', - 'updatedAt', - '_reference' - ]; + '_id', + 'name', + 'filament', + 'filament._id', + 'filamentSku', + 'filamentSku._id', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['name', 'filament', 'filamentSku', 'cost', 'createdAt', 'updatedAt']; const propertiesAllowedFilters = ['filament', 'filament._id', 'filamentSku', 'filamentSku._id']; import { listGCodeFilesRouteHandler, @@ -28,13 +29,13 @@ import { getGCodeFileNeighborsRouteHandler } from '../../services/production/gcodefiles.js'; -import { convertPropertiesString, getFilter } from '../../utils.js'; +import { convertPropertiesString, getFilter, getSort } from '../../utils.js'; // list of gcodeFiles router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listGCodeFilesRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listGCodeFilesRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -70,7 +71,7 @@ router.get('/stats', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getGCodeFileNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getGCodeFileNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/production/jobs.js b/src/routes/production/jobs.js index f6d447a..f2cef2b 100644 --- a/src/routes/production/jobs.js +++ b/src/routes/production/jobs.js @@ -4,14 +4,26 @@ import { isAuthenticated } from '../../keycloak.js'; const router = express.Router(); const listAllowedFilters = [ - 'state', - 'gcodeFile._id', - 'quantity', - '_id', - '_reference', - 'createdAt', - 'updatedAt' - ]; + 'state', + 'gcodeFile', + 'gcodeFile._id', + 'quantity', + '_id', + '_reference', + 'createdAt', + 'updatedAt', + 'startedAt', + 'finishedAt', +]; +const listAllowedSorters = [ + 'createdAt', + 'state', + 'quantity', + 'gcodeFile', + 'updatedAt', + 'startedAt', + 'finishedAt', +]; const propertiesAllowedFilters = ['state']; import { listJobsRouteHandler, @@ -26,13 +38,13 @@ import { getJobPropertyValuesRouteHandler, getJobNeighborsRouteHandler, } from '../../services/production/jobs.js'; -import { convertPropertiesString, getFilter } from '../../utils.js'; +import { convertPropertiesString, getFilter, getSort } from '../../utils.js'; // list of jobs router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listJobsRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listJobsRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -71,7 +83,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getJobNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getJobNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/production/printerprofiles.js b/src/routes/production/printerprofiles.js index a4baa45..a4f78ab 100644 --- a/src/routes/production/printerprofiles.js +++ b/src/routes/production/printerprofiles.js @@ -1,6 +1,6 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { convertPropertiesString, getFilter } from '../../utils.js'; +import { convertPropertiesString, getFilter, getSort } from '../../utils.js'; import { deletePrinterProfileRouteHandler, editPrinterProfileRouteHandler, @@ -16,13 +16,22 @@ import { const router = express.Router(); -const listAllowedFilters = ['_id','name','createdAt','updatedAt','_reference']; +const listAllowedFilters = ['_id', 'name', 'createdAt', 'updatedAt', '_reference']; +const listAllowedSorters = [ + 'name', + 'printBedWidth', + 'printBedHeight', + 'printableHeight', + 'zOffset', + 'createdAt', + 'updatedAt', +]; const propertiesAllowedFilters = ['name']; router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listPrinterProfilesRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listPrinterProfilesRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -51,7 +60,7 @@ router.post('/', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getPrinterProfileNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getPrinterProfileNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/production/printers.js b/src/routes/production/printers.js index 0e185d2..87265a3 100644 --- a/src/routes/production/printers.js +++ b/src/routes/production/printers.js @@ -14,26 +14,28 @@ import { getPrinterPropertyValuesRouteHandler, getPrinterNeighborsRouteHandler, } from '../../services/production/printers.js'; -import { convertPropertiesString, getFilter } from '../../utils.js'; +import { convertPropertiesString, getFilter, getSort } from '../../utils.js'; const listAllowedFilters = [ - 'tags', - 'host._id', - 'active', - 'online', - 'name', - '_id', - '_reference', - 'state', - 'createdAt', - 'updatedAt' - ]; + 'tags', + 'host', + 'host._id', + 'active', + 'online', + 'name', + '_id', + '_reference', + 'state', + 'createdAt', + 'updatedAt', +]; +const listAllowedSorters = ['name', 'state', 'connectedAt', 'createdAt', 'updatedAt', 'host']; const propertiesAllowedFilters = ['tags']; // list of printers router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listPrintersRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listPrintersRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -68,7 +70,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getPrinterNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getPrinterNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); // get printer stats diff --git a/src/routes/production/subjobs.js b/src/routes/production/subjobs.js index b2e1934..515c6db 100644 --- a/src/routes/production/subjobs.js +++ b/src/routes/production/subjobs.js @@ -4,14 +4,27 @@ import { isAuthenticated } from '../../keycloak.js'; const router = express.Router(); const listAllowedFilters = [ - '_id', - 'job._id', - 'printer._id', - '_reference', - 'state', - 'createdAt', - 'updatedAt' - ]; + '_id', + 'job', + 'job._id', + 'printer', + 'printer._id', + '_reference', + 'state', + 'createdAt', + 'updatedAt', + 'startedAt', + 'finishedAt', +]; +const listAllowedSorters = [ + 'createdAt', + 'state', + 'updatedAt', + 'startedAt', + 'finishedAt', + 'job', + 'printer', +]; const propertiesAllowedFilters = ['job']; import { listSubJobsRouteHandler, @@ -23,13 +36,13 @@ import { getSubJobPropertyValuesRouteHandler, getSubJobNeighborsRouteHandler, } from '../../services/production/subjobs.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; // list of sub jobs router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listSubJobsRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listSubJobsRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -64,7 +77,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getSubJobNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getSubJobNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/sales/clients.js b/src/routes/sales/clients.js index 27aef36..17ac72e 100644 --- a/src/routes/sales/clients.js +++ b/src/routes/sales/clients.js @@ -1,17 +1,20 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); -const listAllowedFilters = [ - 'country', - 'active', - 'createdAt', - 'updatedAt', - 'name', - '_reference' - ]; +const listAllowedFilters = ['country', 'active', 'createdAt', 'updatedAt', 'name', '_reference']; +const listAllowedSorters = [ + 'name', + 'country', + 'email', + 'phone', + 'active', + 'createdAt', + 'updatedAt', + '_id', +]; const propertiesAllowedFilters = ['country', 'active', 'createdAt', 'updatedAt']; import { listClientsRouteHandler, @@ -32,7 +35,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listClientsRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listClientsRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -72,7 +75,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getClientNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getClientNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/sales/listings.js b/src/routes/sales/listings.js index 8955c0e..199f745 100644 --- a/src/routes/sales/listings.js +++ b/src/routes/sales/listings.js @@ -1,21 +1,35 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'product', - 'vendor', - 'stockLocation', - 'marketplace', - 'courierServices', - 'state', - 'state.type', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'product', + 'product._id', + 'vendor', + 'vendor._id', + 'stockLocation', + 'stockLocation._id', + 'marketplace', + 'marketplace._id', + 'courierServices', + 'state', + 'state.type', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = [ + 'title', + 'vendor', + 'state', + 'price', + 'lastSyncedAt', + 'createdAt', + 'updatedAt', + '_id', +]; const propertiesAllowedFilters = [ 'product', 'vendor', @@ -47,7 +61,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listListingsRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listListingsRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -92,7 +106,7 @@ router.post('/:id/unpublish', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getListingNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getListingNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/sales/listingvarients.js b/src/routes/sales/listingvarients.js index fa6e2e5..9c01904 100644 --- a/src/routes/sales/listingvarients.js +++ b/src/routes/sales/listingvarients.js @@ -1,20 +1,23 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'listing', - 'listing._id', - 'product', - 'productSku', - 'state', - 'state.type', - 'createdAt', - 'updatedAt', - '_reference' - ]; + 'listing', + 'listing._id', + 'product', + 'product._id', + 'productSku', + 'productSku._id', + 'state', + 'state.type', + 'createdAt', + 'updatedAt', + '_reference', +]; +const listAllowedSorters = ['state', 'price', 'lastSyncedAt', 'createdAt', 'updatedAt', '_id']; const propertiesAllowedFilters = [ 'listing', 'listing._id', @@ -45,7 +48,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listListingVarientsRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listListingVarientsRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -91,7 +94,7 @@ router.post('/:id/unpublish', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getListingVarientNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getListingVarientNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/sales/marketplaces.js b/src/routes/sales/marketplaces.js index b0d1189..90fecb1 100644 --- a/src/routes/sales/marketplaces.js +++ b/src/routes/sales/marketplaces.js @@ -1,20 +1,30 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ - 'name', - 'provider', - 'active', - 'connected', - 'state.type', - 'createdAt', - 'updatedAt', - 'state', - '_reference' - ]; + 'name', + 'provider', + 'active', + 'connected', + 'state.type', + 'createdAt', + 'updatedAt', + 'state', + '_reference', +]; +const listAllowedSorters = [ + 'name', + 'provider', + 'active', + 'connected', + 'state', + 'createdAt', + 'updatedAt', + '_id', +]; const propertiesAllowedFilters = ['name', 'provider', 'active', 'connected', 'state.type', 'createdAt', 'updatedAt']; import { listMarketplacesRouteHandler, @@ -40,7 +50,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listMarketplacesRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listMarketplacesRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -103,7 +113,7 @@ router.post('/:id/hook', async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getMarketplaceNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getMarketplaceNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/routes/sales/salesorders.js b/src/routes/sales/salesorders.js index 2d22208..df1f9c2 100644 --- a/src/routes/sales/salesorders.js +++ b/src/routes/sales/salesorders.js @@ -1,18 +1,19 @@ import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; -import { getFilter, convertPropertiesString } from '../../utils.js'; +import { getFilter, convertPropertiesString, getSort } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ 'client', + 'client._id', 'state', 'value', - 'client._id', 'createdAt', 'updatedAt', '_reference', ]; +const listAllowedSorters = ['createdAt', 'state', 'updatedAt']; const propertiesAllowedFilters = ['client', 'state.type', 'value', 'client._id']; import { listSalesOrdersRouteHandler, @@ -36,7 +37,7 @@ import { router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - listSalesOrdersRouteHandler(req, res, page, limit, property, filter, search, sort, order); + listSalesOrdersRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order); }); router.get('/properties', isAuthenticated, async (req, res) => { @@ -75,7 +76,7 @@ router.get('/history', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); - getSalesOrderNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); + getSalesOrderNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { diff --git a/src/utils.js b/src/utils.js index dc189c1..416f239 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1550,6 +1550,14 @@ function mergeFilterClauses(clauses) { return needsAnd ? { $and: valid } : Object.assign({}, ...valid); } +// Returns a validated sort field based on allowed sorters +function getSort(sort, allowedSorters, defaultSort = 'createdAt') { + if (sort && allowedSorters.includes(sort)) { + return sort; + } + return defaultSort; +} + // Returns a filter object based on allowed filters and req.query async function getFilter(query, allowedFilters, parse = true, model = null) { const clauses = []; @@ -1729,7 +1737,8 @@ export { notfiyObjectUserNotifiers, createNotification, sendEmailNotification, - getFilter, // <-- add here + getFilter, + getSort, convertPropertiesString, getFileMeta, modelHasRef,