Add sorting functionality to various inventory and management routes
All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good

This update introduces a new utility function, `getSort`, to validate and apply sorting based on allowed sorters across multiple routes in the inventory and management modules. The function is integrated into route handlers for invoices, payments, tax records, filament stocks, order items, part stocks, product stocks, purchase orders, shipments, and various management entities. This enhancement improves the flexibility and consistency of sorting operations throughout the application.
This commit is contained in:
Tom Butcher 2026-08-11 02:12:27 +01:00
parent 3d4150c6cc
commit aa4b173a7e
48 changed files with 694 additions and 518 deletions

View File

@ -1,22 +1,23 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'vendor', 'vendor',
'client', 'client',
'state', 'state',
'vendor._id', 'vendor._id',
'client._id', 'client._id',
'order', 'order',
'order._id', 'order._id',
'orderType', 'orderType',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = ['createdAt', 'state', 'updatedAt', 'invoiceDate', 'dueDate'];
const propertiesAllowedFilters = [ const propertiesAllowedFilters = [
'vendor', 'vendor',
'client', 'client',
@ -50,7 +51,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,21 +1,22 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'vendor', 'vendor',
'client', 'client',
'state', 'state',
'vendor._id', 'vendor._id',
'client._id', 'client._id',
'invoice', 'invoice',
'invoice._id', 'invoice._id',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = ['createdAt', 'state', 'updatedAt', 'paymentDate'];
const propertiesAllowedFilters = [ const propertiesAllowedFilters = [
'vendor', 'vendor',
'client', 'client',
@ -50,7 +51,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,18 +1,21 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'taxRate', 'taxRate',
'transactionType', 'taxRate._id',
'transaction', 'transactionType',
'transactionDate', 'transaction',
'createdAt', 'transaction._id',
'updatedAt', 'transactionDate',
'_reference' 'createdAt',
]; 'updatedAt',
'_reference',
];
const listAllowedSorters = ['transactionDate', 'amount', 'taxAmount', 'createdAt', '_id', 'updatedAt'];
const propertiesAllowedFilters = ['taxRate', 'transactionType', 'transaction']; const propertiesAllowedFilters = ['taxRate', 'transactionType', 'transaction'];
import { import {
listTaxRecordsRouteHandler, listTaxRecordsRouteHandler,
@ -33,7 +36,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,23 +1,24 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'filament', 'filament',
'filament._id', 'filament._id',
'filamentSku', 'filamentSku',
'state', 'filamentSku._id',
'startingWeight', 'state',
'currentWeight', 'startingWeight',
'filamentSku._id', 'currentWeight',
'stockLocation', 'stockLocation',
'stockLocation._id', 'stockLocation._id',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = ['createdAt', 'updatedAt', 'filament', 'filamentSku', 'state'];
const propertiesAllowedFilters = [ const propertiesAllowedFilters = [
'filament', 'filament',
'filament._id', 'filament._id',
@ -45,7 +46,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,6 +1,6 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
@ -19,6 +19,7 @@ const listAllowedFilters = [
'updatedAt', 'updatedAt',
'_reference', '_reference',
]; ];
const listAllowedSorters = ['createdAt', 'updatedAt', 'itemAmount', 'quantity', 'state', 'name'];
const propertiesAllowedFilters = [ const propertiesAllowedFilters = [
'name', 'name',
'itemType', 'itemType',
@ -49,7 +50,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,21 +1,22 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'partSku', 'partSku',
'state', 'partSku._id',
'startingQuantity', 'state',
'currentQuantity', 'startingQuantity',
'partSku._id', 'currentQuantity',
'stockLocation', 'stockLocation',
'stockLocation._id', 'stockLocation._id',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = ['partSku', 'startingQuantity', 'currentQuantity', 'state', 'createdAt', 'updatedAt'];
const propertiesAllowedFilters = ['part', 'state.type']; const propertiesAllowedFilters = ['part', 'state.type'];
import { import {
listPartStocksRouteHandler, listPartStocksRouteHandler,
@ -37,7 +38,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,20 +1,21 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'productSku', 'productSku',
'state', 'productSku._id',
'currentQuantity', 'state',
'productSku._id', 'currentQuantity',
'stockLocation', 'stockLocation',
'stockLocation._id', 'stockLocation._id',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = ['productSku', 'currentQuantity', 'state', 'createdAt', 'updatedAt'];
const propertiesAllowedFilters = ['productSku', 'state.type']; const propertiesAllowedFilters = ['productSku', 'state.type'];
import { import {
listProductStocksRouteHandler, listProductStocksRouteHandler,
@ -36,7 +37,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,14 +1,14 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'vendor', 'vendor',
'vendor._id',
'state', 'state',
'value', 'value',
'vendor._id',
'totalAmount', 'totalAmount',
'totalAmountWithTax', 'totalAmountWithTax',
'totalTaxAmount', 'totalTaxAmount',
@ -19,6 +19,17 @@ const listAllowedFilters = [
'updatedAt', 'updatedAt',
'_reference', '_reference',
]; ];
const listAllowedSorters = [
'createdAt',
'state',
'updatedAt',
'totalAmount',
'totalAmountWithTax',
'totalTaxAmount',
'shippingAmount',
'shippingAmountWithTax',
'grandTotalAmount',
];
const propertiesAllowedFilters = [ const propertiesAllowedFilters = [
'vendor', 'vendor',
'state.type', 'state.type',
@ -53,7 +64,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,20 +1,23 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'orderType', 'orderType',
'order', 'order',
'order._id',
'state', 'state',
'courierService', 'courierService',
'order._id', 'courierService._id',
'taxRate', 'taxRate',
'taxRate._id',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference', '_reference',
]; ];
const listAllowedSorters = ['createdAt', 'state', 'updatedAt', 'shippedAt', 'expectedAt', 'deliveredAt'];
const propertiesAllowedFilters = [ const propertiesAllowedFilters = [
'orderType', 'orderType',
'order', 'order',
@ -45,7 +48,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,6 +1,6 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { parseFilter, getFilter } from '../../utils.js'; import { parseFilter, getFilter, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
import { import {
@ -16,14 +16,15 @@ import {
} from '../../services/inventory/stockaudits.js'; } from '../../services/inventory/stockaudits.js';
const listAllowedFilters = [ const listAllowedFilters = [
'status', 'status',
'type', 'type',
'createdBy', 'createdBy',
'state', 'state',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = ['createdAt', 'updatedAt', 'state'];
// List stock audits // List stock audits
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
@ -66,7 +67,7 @@ router.get('/history', isAuthenticated, async (req, res) => {
router.get('/neighbors', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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 // Get specific stock audit

View File

@ -1,16 +1,11 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = ['owner._id', 'parent._id', 'createdAt', 'updatedAt', '_reference'];
'owner._id', const listAllowedSorters = ['createdAt', 'updatedAt'];
'parent._id',
'createdAt',
'updatedAt',
'_reference'
];
const propertiesAllowedFilters = ['owner._id', 'parent._id']; const propertiesAllowedFilters = ['owner._id', 'parent._id'];
import { import {
listStockEventsRouteHandler, listStockEventsRouteHandler,
@ -32,7 +27,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, sort, order } = req.query; const { page, limit, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,10 +1,11 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = ['name','createdAt','updatedAt','_reference']; const listAllowedFilters = ['name', 'createdAt', 'updatedAt', '_reference'];
const listAllowedSorters = ['name', 'createdAt', 'updatedAt'];
const propertiesAllowedFilters = ['name']; const propertiesAllowedFilters = ['name'];
import { import {
listStockLocationsRouteHandler, listStockLocationsRouteHandler,
@ -25,7 +26,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,18 +1,19 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'state', 'state',
'state.type', 'state.type',
'postedAt', 'postedAt',
'name', 'name',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = ['name', 'createdAt', 'postedAt', 'state', 'updatedAt'];
const propertiesAllowedFilters = ['state.type']; const propertiesAllowedFilters = ['state.type'];
import { import {
listStockTransfersRouteHandler, listStockTransfersRouteHandler,
@ -34,7 +35,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,19 +1,20 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'_id', '_id',
'name', 'name',
'user', 'user',
'active', 'user._id',
'user._id', 'active',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = ['name', 'user', 'active', 'createdAt', 'updatedAt'];
const propertiesAllowedFilters = ['name', 'user', 'active']; const propertiesAllowedFilters = ['name', 'user', 'active'];
import { import {
listAppPasswordsRouteHandler, listAppPasswordsRouteHandler,
@ -34,7 +35,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -7,37 +7,19 @@ import {
getAuditLogHistoryRouteHandler, getAuditLogHistoryRouteHandler,
searchAuditLogsRouteHandler, searchAuditLogsRouteHandler,
} from '../../services/management/auditlogs.js'; } from '../../services/management/auditlogs.js';
import { parseFilter } from '../../utils.js'; import { getFilter, getSort } from '../../utils.js';
const router = express.Router(); 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) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, sort, order } = req.query; const { page, limit, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters);
const allowedFilters = [ listAuditLogsRouteHandler(req, res, page, limit, filter, getSort(sort, listAllowedSorters), order);
'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);
}); });
// get audit log stats
router.get('/search', isAuthenticated, async (req, res) => { router.get('/search', isAuthenticated, async (req, res) => {
const { search } = req.query; const { search } = req.query;
searchAuditLogsRouteHandler(req, res, search); searchAuditLogsRouteHandler(req, res, search);
@ -47,16 +29,10 @@ router.get('/stats', isAuthenticated, async (req, res) => {
getAuditLogStatsRouteHandler(req, res); getAuditLogStatsRouteHandler(req, res);
}); });
// get audit log history
router.get('/history', isAuthenticated, async (req, res) => { router.get('/history', isAuthenticated, async (req, res) => {
getAuditLogHistoryRouteHandler(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) => { router.get('/:id', async (req, res) => {
await getAuditLogRouteHandler(req, res); await getAuditLogRouteHandler(req, res);
}); });

View File

@ -1,20 +1,21 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'name', 'name',
'website', 'website',
'email', 'email',
'phone', 'phone',
'contact', 'contact',
'country', 'country',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = ['name', 'country', 'email', 'createdAt', '_id', 'updatedAt'];
const propertiesAllowedFilters = ['name', 'website', 'email', 'phone', 'contact', 'country']; const propertiesAllowedFilters = ['name', 'website', 'email', 'phone', 'contact', 'country'];
import { import {
listCouriersRouteHandler, listCouriersRouteHandler,
@ -35,7 +36,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,23 +1,35 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'_id', '_id',
'courier', 'courier',
'courier._id', 'courier._id',
'name', 'name',
'active', 'active',
'tracked', 'tracked',
'deliveryTime', 'deliveryTime',
'cost', 'cost',
'costWithTax', 'costWithTax',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = [
'name',
'courier',
'active',
'tracked',
'cost',
'costWithTax',
'estimatedDeliveryTime',
'createdAt',
'_id',
'updatedAt',
];
const propertiesAllowedFilters = [ const propertiesAllowedFilters = [
'_id', '_id',
'courier', 'courier',
@ -48,7 +60,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,18 +1,19 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'name', 'name',
'width', 'width',
'height', 'height',
'state', 'state',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = ['name', 'state', 'createdAt', 'updatedAt'];
const propertiesAllowedFilters = []; const propertiesAllowedFilters = [];
import { import {
listDocumentJobsRouteHandler, listDocumentJobsRouteHandler,
@ -33,7 +34,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,19 +1,20 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'name', 'name',
'tags', 'tags',
'active', 'active',
'isGlobal', 'isGlobal',
'state', 'state',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = ['name', 'documentSize', 'connectedAt', 'updatedAt', 'state', 'createdAt'];
const propertiesAllowedFilters = ['tags']; const propertiesAllowedFilters = ['tags'];
import { import {
listDocumentPrintersRouteHandler, listDocumentPrintersRouteHandler,
@ -34,7 +35,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,17 +1,11 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = ['name', 'width', 'height', 'createdAt', 'updatedAt', '_reference'];
'name', const listAllowedSorters = ['name', 'width', 'height', 'infiniteHeight', 'createdAt', 'updatedAt'];
'width',
'height',
'createdAt',
'updatedAt',
'_reference'
];
const propertiesAllowedFilters = []; const propertiesAllowedFilters = [];
import { import {
listDocumentSizesRouteHandler, listDocumentSizesRouteHandler,
@ -32,7 +26,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,19 +1,33 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'name', 'name',
'tags', 'tags',
'active', 'active',
'global', 'global',
'objectType', 'parent',
'createdAt', 'parent._id',
'updatedAt', 'documentSize',
'_reference' 'documentSize._id',
]; 'objectType',
'createdAt',
'updatedAt',
'_reference',
];
const listAllowedSorters = [
'name',
'parent',
'documentSize',
'createdAt',
'updatedAt',
'active',
'global',
'objectType',
];
const propertiesAllowedFilters = ['documentSize', 'tags']; const propertiesAllowedFilters = ['documentSize', 'tags'];
import { import {
listDocumentTemplatesRouteHandler, listDocumentTemplatesRouteHandler,
@ -33,7 +47,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,20 +1,29 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; 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 router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'_id', '_id',
'material', 'material',
'material._id', 'material._id',
'diameter', 'diameter',
'name', 'name',
'cost', 'cost',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = [
'name',
'createdAt',
'vendor',
'material',
'cost',
'costWithTax',
'updatedAt',
];
const propertiesAllowedFilters = ['diameter', 'material']; const propertiesAllowedFilters = ['diameter', 'material'];
import { import {
listFilamentsRouteHandler, 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,6 +1,6 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
@ -17,6 +17,16 @@ const listAllowedFilters = [
'updatedAt', 'updatedAt',
'_reference', '_reference',
]; ];
const listAllowedSorters = [
'barcode',
'filament',
'name',
'color',
'cost',
'costWithTax',
'createdAt',
'updatedAt',
];
const propertiesAllowedFilters = ['filament', 'filament._id', 'diameter']; const propertiesAllowedFilters = ['filament', 'filament._id', 'diameter'];
import { import {
listFilamentSkusRouteHandler, listFilamentSkusRouteHandler,
@ -35,7 +45,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,19 +1,20 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'_id', '_id',
'name', 'name',
'type', 'type',
'size', 'size',
'extension', 'extension',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = ['name', 'type', 'size', 'createdAt', 'temp', 'updatedAt'];
const propertiesAllowedFilters = ['type', 'extension']; const propertiesAllowedFilters = ['type', 'extension'];
import { import {
listFilesRouteHandler, listFilesRouteHandler,
@ -37,7 +38,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,18 +1,20 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'_id', 'name',
'name', '_id',
'tags', 'state',
'state', 'tags',
'createdAt', 'connectedAt',
'updatedAt', 'createdAt',
'_reference' 'updatedAt',
]; '_reference',
];
const listAllowedSorters = ['name', 'state', 'connectedAt', 'createdAt', 'updatedAt'];
const propertiesAllowedFilters = ['tags']; const propertiesAllowedFilters = ['tags'];
import { import {
listHostsRouteHandler, listHostsRouteHandler,
@ -32,7 +34,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,17 +1,11 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; 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 router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = ['_id', 'name', 'tags', 'createdAt', 'updatedAt', '_reference'];
'_id', const listAllowedSorters = ['name', 'createdAt', 'updatedAt', '_id'];
'name',
'tags',
'createdAt',
'updatedAt',
'_reference'
];
const propertiesAllowedFilters = ['name', 'tags']; const propertiesAllowedFilters = ['name', 'tags'];
import { import {
listMaterialsRouteHandler, 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,18 +1,19 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'_id', 'name',
'name', '_id',
'active', 'color',
'color', 'active',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = ['name', 'color', 'active', 'createdAt', 'updatedAt'];
const propertiesAllowedFilters = ['active', 'color']; const propertiesAllowedFilters = ['active', 'color'];
import { import {
listNoteTypesRouteHandler, listNoteTypesRouteHandler,
@ -33,7 +34,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,17 +1,21 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = ['product._id', '_id', 'name', 'createdAt', 'updatedAt', '_reference'];
'product._id', const listAllowedSorters = [
'_id', 'name',
'name', 'priceMode',
'createdAt', 'cost',
'updatedAt', 'costWithTax',
'_reference' 'price',
]; 'priceWithTax',
'createdAt',
'updatedAt',
'_id',
];
const propertiesAllowedFilters = ['product._id']; const propertiesAllowedFilters = ['product._id'];
import { import {
listPartsRouteHandler, listPartsRouteHandler,
@ -32,7 +36,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,21 +1,32 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'_id', '_id',
'barcode', 'barcode',
'part', 'part',
'part._id', 'part._id',
'name', 'name',
'cost', 'cost',
'price', 'price',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = [
'barcode',
'part',
'name',
'cost',
'costWithTax',
'price',
'priceWithTax',
'createdAt',
'updatedAt',
];
const propertiesAllowedFilters = ['part', 'part._id']; const propertiesAllowedFilters = ['part', 'part._id'];
import { import {
listPartSkusRouteHandler, listPartSkusRouteHandler,
@ -35,7 +46,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,6 +1,6 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { convertPropertiesString, getFilter } from '../../utils.js'; import { convertPropertiesString, getFilter, getSort } from '../../utils.js';
import { import {
deleteProductCategoryRouteHandler, deleteProductCategoryRouteHandler,
editProductCategoryRouteHandler, editProductCategoryRouteHandler,
@ -18,13 +18,14 @@ import {
const router = express.Router(); 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']; const propertiesAllowedFilters = ['name'];
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,19 +1,31 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'_id', '_id',
'name', 'name',
'globalPrice', 'globalPrice',
'productCategory', 'productCategory',
'productCategory._id', 'productCategory._id',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = [
'name',
'productCategory',
'createdAt',
'type',
'vendor',
'cost',
'costWithTax',
'price',
'priceWithTax',
'updatedAt',
];
const propertiesAllowedFilters = []; const propertiesAllowedFilters = [];
import { import {
listProductsRouteHandler, listProductsRouteHandler,
@ -34,7 +46,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,21 +1,32 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'_id', '_id',
'barcode', 'barcode',
'product', 'product',
'product._id', 'product._id',
'name', 'name',
'cost', 'cost',
'price', 'price',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = [
'barcode',
'product',
'name',
'cost',
'costWithTax',
'price',
'priceWithTax',
'createdAt',
'updatedAt',
];
const propertiesAllowedFilters = ['product', 'product._id']; const propertiesAllowedFilters = ['product', 'product._id'];
import { import {
listProductSkusRouteHandler, listProductSkusRouteHandler,
@ -35,7 +46,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,19 +1,29 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'name', 'name',
'rate', 'rate',
'rateType', 'rateType',
'active', 'active',
'country', 'country',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = [
'name',
'rate',
'rateType',
'active',
'country',
'createdAt',
'_id',
'updatedAt',
];
const propertiesAllowedFilters = ['rateType', 'country', 'active']; const propertiesAllowedFilters = ['rateType', 'country', 'active'];
import { import {
listTaxRatesRouteHandler, listTaxRatesRouteHandler,
@ -34,7 +44,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,19 +1,20 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { convertPropertiesString, getFilter } from '../../utils.js'; import { convertPropertiesString, getFilter, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'name', 'name',
'username', 'username',
'firstName', 'firstName',
'lastName', 'lastName',
'email', 'email',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = ['name', 'email', 'role', 'createdAt', '_id', 'updatedAt'];
const propertiesAllowedFilters = []; const propertiesAllowedFilters = [];
import { import {
listUsersRouteHandler, listUsersRouteHandler,
@ -33,7 +34,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,17 +1,19 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = ['country', 'active', 'createdAt', 'updatedAt', 'name', '_reference'];
'country', const listAllowedSorters = [
'active', 'name',
'createdAt', 'country',
'updatedAt', 'email',
'name', 'active',
'_reference' 'createdAt',
]; 'updatedAt',
'_id',
];
const propertiesAllowedFilters = ['country', 'active', 'createdAt', 'updatedAt']; const propertiesAllowedFilters = ['country', 'active', 'createdAt', 'updatedAt'];
import { import {
listVendorsRouteHandler, listVendorsRouteHandler,
@ -32,7 +34,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -13,23 +13,31 @@ import {
getNoteNeighborsRouteHandler getNoteNeighborsRouteHandler
} from '../../services/misc/notes.js'; } from '../../services/misc/notes.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'parent._id', '_id',
'createdAt', 'user',
'updatedAt', 'user._id',
'_reference' 'parentType',
]; 'parent',
'parent._id',
'noteType',
'noteType._id',
'createdAt',
'updatedAt',
'_reference',
];
const listAllowedSorters = ['createdAt', 'updatedAt', 'parentType', 'noteType'];
const propertiesAllowedFilters = ['parent']; const propertiesAllowedFilters = ['parent'];
// list of notes // list of notes
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,6 +1,6 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { convertPropertiesString, getFilter } from '../../utils.js'; import { convertPropertiesString, getFilter, getSort } from '../../utils.js';
import { import {
deleteFilamentProfileRouteHandler, deleteFilamentProfileRouteHandler,
editFilamentProfileRouteHandler, editFilamentProfileRouteHandler,
@ -16,13 +16,14 @@ import {
const router = express.Router(); 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']; const propertiesAllowedFilters = ['name'];
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/properties', isAuthenticated, async (req, res) => {
@ -51,7 +52,7 @@ router.post('/', isAuthenticated, async (req, res) => {
router.get('/neighbors', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -4,16 +4,17 @@ import { isAuthenticated } from '../../keycloak.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'_id', '_id',
'name', 'name',
'filament', 'filament',
'filament._id', 'filament._id',
'filamentSku', 'filamentSku',
'filamentSku._id', 'filamentSku._id',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference' '_reference',
]; ];
const listAllowedSorters = ['name', 'filament', 'filamentSku', 'cost', 'createdAt', 'updatedAt'];
const propertiesAllowedFilters = ['filament', 'filament._id', 'filamentSku', 'filamentSku._id']; const propertiesAllowedFilters = ['filament', 'filament._id', 'filamentSku', 'filamentSku._id'];
import { import {
listGCodeFilesRouteHandler, listGCodeFilesRouteHandler,
@ -28,13 +29,13 @@ import {
getGCodeFileNeighborsRouteHandler getGCodeFileNeighborsRouteHandler
} from '../../services/production/gcodefiles.js'; } from '../../services/production/gcodefiles.js';
import { convertPropertiesString, getFilter } from '../../utils.js'; import { convertPropertiesString, getFilter, getSort } from '../../utils.js';
// list of gcodeFiles // list of gcodeFiles
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -4,14 +4,26 @@ import { isAuthenticated } from '../../keycloak.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'state', 'state',
'gcodeFile._id', 'gcodeFile',
'quantity', 'gcodeFile._id',
'_id', 'quantity',
'_reference', '_id',
'createdAt', '_reference',
'updatedAt' 'createdAt',
]; 'updatedAt',
'startedAt',
'finishedAt',
];
const listAllowedSorters = [
'createdAt',
'state',
'quantity',
'gcodeFile',
'updatedAt',
'startedAt',
'finishedAt',
];
const propertiesAllowedFilters = ['state']; const propertiesAllowedFilters = ['state'];
import { import {
listJobsRouteHandler, listJobsRouteHandler,
@ -26,13 +38,13 @@ import {
getJobPropertyValuesRouteHandler, getJobPropertyValuesRouteHandler,
getJobNeighborsRouteHandler, getJobNeighborsRouteHandler,
} from '../../services/production/jobs.js'; } from '../../services/production/jobs.js';
import { convertPropertiesString, getFilter } from '../../utils.js'; import { convertPropertiesString, getFilter, getSort } from '../../utils.js';
// list of jobs // list of jobs
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,6 +1,6 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { convertPropertiesString, getFilter } from '../../utils.js'; import { convertPropertiesString, getFilter, getSort } from '../../utils.js';
import { import {
deletePrinterProfileRouteHandler, deletePrinterProfileRouteHandler,
editPrinterProfileRouteHandler, editPrinterProfileRouteHandler,
@ -16,13 +16,22 @@ import {
const router = express.Router(); 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']; const propertiesAllowedFilters = ['name'];
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/properties', isAuthenticated, async (req, res) => {
@ -51,7 +60,7 @@ router.post('/', isAuthenticated, async (req, res) => {
router.get('/neighbors', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -14,26 +14,28 @@ import {
getPrinterPropertyValuesRouteHandler, getPrinterPropertyValuesRouteHandler,
getPrinterNeighborsRouteHandler, getPrinterNeighborsRouteHandler,
} from '../../services/production/printers.js'; } from '../../services/production/printers.js';
import { convertPropertiesString, getFilter } from '../../utils.js'; import { convertPropertiesString, getFilter, getSort } from '../../utils.js';
const listAllowedFilters = [ const listAllowedFilters = [
'tags', 'tags',
'host._id', 'host',
'active', 'host._id',
'online', 'active',
'name', 'online',
'_id', 'name',
'_reference', '_id',
'state', '_reference',
'createdAt', 'state',
'updatedAt' 'createdAt',
]; 'updatedAt',
];
const listAllowedSorters = ['name', 'state', 'connectedAt', 'createdAt', 'updatedAt', 'host'];
const propertiesAllowedFilters = ['tags']; const propertiesAllowedFilters = ['tags'];
// list of printers // list of printers
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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 // get printer stats

View File

@ -4,14 +4,27 @@ import { isAuthenticated } from '../../keycloak.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'_id', '_id',
'job._id', 'job',
'printer._id', 'job._id',
'_reference', 'printer',
'state', 'printer._id',
'createdAt', '_reference',
'updatedAt' 'state',
]; 'createdAt',
'updatedAt',
'startedAt',
'finishedAt',
];
const listAllowedSorters = [
'createdAt',
'state',
'updatedAt',
'startedAt',
'finishedAt',
'job',
'printer',
];
const propertiesAllowedFilters = ['job']; const propertiesAllowedFilters = ['job'];
import { import {
listSubJobsRouteHandler, listSubJobsRouteHandler,
@ -23,13 +36,13 @@ import {
getSubJobPropertyValuesRouteHandler, getSubJobPropertyValuesRouteHandler,
getSubJobNeighborsRouteHandler, getSubJobNeighborsRouteHandler,
} from '../../services/production/subjobs.js'; } from '../../services/production/subjobs.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
// list of sub jobs // list of sub jobs
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,17 +1,20 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = ['country', 'active', 'createdAt', 'updatedAt', 'name', '_reference'];
'country', const listAllowedSorters = [
'active', 'name',
'createdAt', 'country',
'updatedAt', 'email',
'name', 'phone',
'_reference' 'active',
]; 'createdAt',
'updatedAt',
'_id',
];
const propertiesAllowedFilters = ['country', 'active', 'createdAt', 'updatedAt']; const propertiesAllowedFilters = ['country', 'active', 'createdAt', 'updatedAt'];
import { import {
listClientsRouteHandler, listClientsRouteHandler,
@ -32,7 +35,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,21 +1,35 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'product', 'product',
'vendor', 'product._id',
'stockLocation', 'vendor',
'marketplace', 'vendor._id',
'courierServices', 'stockLocation',
'state', 'stockLocation._id',
'state.type', 'marketplace',
'createdAt', 'marketplace._id',
'updatedAt', 'courierServices',
'_reference' 'state',
]; 'state.type',
'createdAt',
'updatedAt',
'_reference',
];
const listAllowedSorters = [
'title',
'vendor',
'state',
'price',
'lastSyncedAt',
'createdAt',
'updatedAt',
'_id',
];
const propertiesAllowedFilters = [ const propertiesAllowedFilters = [
'product', 'product',
'vendor', 'vendor',
@ -47,7 +61,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,20 +1,23 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'listing', 'listing',
'listing._id', 'listing._id',
'product', 'product',
'productSku', 'product._id',
'state', 'productSku',
'state.type', 'productSku._id',
'createdAt', 'state',
'updatedAt', 'state.type',
'_reference' 'createdAt',
]; 'updatedAt',
'_reference',
];
const listAllowedSorters = ['state', 'price', 'lastSyncedAt', 'createdAt', 'updatedAt', '_id'];
const propertiesAllowedFilters = [ const propertiesAllowedFilters = [
'listing', 'listing',
'listing._id', 'listing._id',
@ -45,7 +48,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,20 +1,30 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'name', 'name',
'provider', 'provider',
'active', 'active',
'connected', 'connected',
'state.type', 'state.type',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'state', 'state',
'_reference' '_reference',
]; ];
const listAllowedSorters = [
'name',
'provider',
'active',
'connected',
'state',
'createdAt',
'updatedAt',
'_id',
];
const propertiesAllowedFilters = ['name', 'provider', 'active', 'connected', 'state.type', 'createdAt', 'updatedAt']; const propertiesAllowedFilters = ['name', 'provider', 'active', 'connected', 'state.type', 'createdAt', 'updatedAt'];
import { import {
listMarketplacesRouteHandler, listMarketplacesRouteHandler,
@ -40,7 +50,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1,18 +1,19 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../keycloak.js'; import { isAuthenticated } from '../../keycloak.js';
import { getFilter, convertPropertiesString } from '../../utils.js'; import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
const router = express.Router(); const router = express.Router();
const listAllowedFilters = [ const listAllowedFilters = [
'client', 'client',
'client._id',
'state', 'state',
'value', 'value',
'client._id',
'createdAt', 'createdAt',
'updatedAt', 'updatedAt',
'_reference', '_reference',
]; ];
const listAllowedSorters = ['createdAt', 'state', 'updatedAt'];
const propertiesAllowedFilters = ['client', 'state.type', 'value', 'client._id']; const propertiesAllowedFilters = ['client', 'state.type', 'value', 'client._id'];
import { import {
listSalesOrdersRouteHandler, listSalesOrdersRouteHandler,
@ -36,7 +37,7 @@ import {
router.get('/', isAuthenticated, async (req, res) => { router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, property, search, sort, order } = req.query; const { page, limit, property, search, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { 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) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sort, order, id } = req.query; const { property, search, sort, order, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); 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) => { router.get('/:id', isAuthenticated, async (req, res) => {

View File

@ -1550,6 +1550,14 @@ function mergeFilterClauses(clauses) {
return needsAnd ? { $and: valid } : Object.assign({}, ...valid); 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 // Returns a filter object based on allowed filters and req.query
async function getFilter(query, allowedFilters, parse = true, model = null) { async function getFilter(query, allowedFilters, parse = true, model = null) {
const clauses = []; const clauses = [];
@ -1729,7 +1737,8 @@ export {
notfiyObjectUserNotifiers, notfiyObjectUserNotifiers,
createNotification, createNotification,
sendEmailNotification, sendEmailNotification,
getFilter, // <-- add here getFilter,
getSort,
convertPropertiesString, convertPropertiesString,
getFileMeta, getFileMeta,
modelHasRef, modelHasRef,