Refactor allowed filters and sorters across various routes to enhance data handling
All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good
All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good
This commit updates the allowed filters and sorters in multiple routes, including invoices, payment policies, inventory, management, and sales. It removes unnecessary filters, adds new ones for improved categorization, and ensures consistency in the data structure. These changes aim to streamline data retrieval and enhance the overall functionality of the application.
This commit is contained in:
parent
a7b613c88b
commit
850c721867
@ -12,10 +12,6 @@ const listAllowedFilters = [
|
|||||||
'state',
|
'state',
|
||||||
'vendor._id',
|
'vendor._id',
|
||||||
'client._id',
|
'client._id',
|
||||||
'from',
|
|
||||||
'from._id',
|
|
||||||
'to',
|
|
||||||
'to._id',
|
|
||||||
'order',
|
'order',
|
||||||
'order._id',
|
'order._id',
|
||||||
'orderType',
|
'orderType',
|
||||||
@ -27,10 +23,6 @@ const listAllowedSorters = ['createdAt', 'state', 'updatedAt', 'invoiceDate', 'd
|
|||||||
const propertiesAllowedFilters = [
|
const propertiesAllowedFilters = [
|
||||||
'vendor',
|
'vendor',
|
||||||
'client',
|
'client',
|
||||||
'from',
|
|
||||||
'from._id',
|
|
||||||
'to',
|
|
||||||
'to._id',
|
|
||||||
'orderType',
|
'orderType',
|
||||||
'order',
|
'order',
|
||||||
'order._id',
|
'order._id',
|
||||||
|
|||||||
@ -21,13 +21,12 @@ const router = express.Router();
|
|||||||
const listAllowedFilters = [
|
const listAllowedFilters = [
|
||||||
'name',
|
'name',
|
||||||
'immediatePay',
|
'immediatePay',
|
||||||
'marketplaces.marketplace',
|
|
||||||
'createdAt',
|
'createdAt',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
'_reference',
|
'_reference',
|
||||||
];
|
];
|
||||||
const listAllowedSorters = ['name', 'immediatePay', 'createdAt', '_id', 'updatedAt'];
|
const listAllowedSorters = ['name', 'immediatePay', 'createdAt', '_id', 'updatedAt'];
|
||||||
const propertiesAllowedFilters = ['name', 'immediatePay', 'marketplaces.marketplace'];
|
const propertiesAllowedFilters = ['name', 'immediatePay'];
|
||||||
|
|
||||||
router.get('/', isAuthenticated, checkPermissions('paymentPolicy', 'list'), async (req, res) => {
|
router.get('/', isAuthenticated, checkPermissions('paymentPolicy', 'list'), async (req, res) => {
|
||||||
const { page, limit, property, search, sortProperty, sortOrder } = req.query;
|
const { page, limit, property, search, sortProperty, sortOrder } = req.query;
|
||||||
|
|||||||
@ -6,6 +6,8 @@ import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
|
|||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
const listAllowedFilters = [
|
const listAllowedFilters = [
|
||||||
|
'part',
|
||||||
|
'part._id',
|
||||||
'partSku',
|
'partSku',
|
||||||
'partSku._id',
|
'partSku._id',
|
||||||
'state',
|
'state',
|
||||||
@ -16,7 +18,14 @@ const listAllowedFilters = [
|
|||||||
'updatedAt',
|
'updatedAt',
|
||||||
'_reference',
|
'_reference',
|
||||||
];
|
];
|
||||||
const listAllowedSorters = ['partSku', 'currentQuantity', 'state', 'createdAt', 'updatedAt'];
|
const listAllowedSorters = [
|
||||||
|
'part',
|
||||||
|
'partSku',
|
||||||
|
'currentQuantity',
|
||||||
|
'state',
|
||||||
|
'createdAt',
|
||||||
|
'updatedAt',
|
||||||
|
];
|
||||||
const propertiesAllowedFilters = ['part', 'state.type'];
|
const propertiesAllowedFilters = ['part', 'state.type'];
|
||||||
import {
|
import {
|
||||||
listPartStocksRouteHandler,
|
listPartStocksRouteHandler,
|
||||||
|
|||||||
@ -6,6 +6,8 @@ import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
|
|||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
const listAllowedFilters = [
|
const listAllowedFilters = [
|
||||||
|
'product',
|
||||||
|
'product._id',
|
||||||
'productSku',
|
'productSku',
|
||||||
'productSku._id',
|
'productSku._id',
|
||||||
'state',
|
'state',
|
||||||
@ -16,8 +18,16 @@ const listAllowedFilters = [
|
|||||||
'updatedAt',
|
'updatedAt',
|
||||||
'_reference',
|
'_reference',
|
||||||
];
|
];
|
||||||
const listAllowedSorters = ['productSku', 'currentQuantity', 'state', 'createdAt', 'updatedAt'];
|
const listAllowedSorters = [
|
||||||
const propertiesAllowedFilters = ['productSku', 'state.type'];
|
'product',
|
||||||
|
'productSku',
|
||||||
|
'currentQuantity',
|
||||||
|
'state',
|
||||||
|
'createdAt',
|
||||||
|
'updatedAt',
|
||||||
|
'stockLocation',
|
||||||
|
];
|
||||||
|
const propertiesAllowedFilters = ['product', 'productSku', 'state.type'];
|
||||||
import {
|
import {
|
||||||
listProductStocksRouteHandler,
|
listProductStocksRouteHandler,
|
||||||
getProductStockRouteHandler,
|
getProductStockRouteHandler,
|
||||||
|
|||||||
@ -8,6 +8,8 @@ const router = express.Router();
|
|||||||
const listAllowedFilters = [
|
const listAllowedFilters = [
|
||||||
'state',
|
'state',
|
||||||
'state.type',
|
'state.type',
|
||||||
|
'fromLocation',
|
||||||
|
'toLocation',
|
||||||
'postedAt',
|
'postedAt',
|
||||||
'createdAt',
|
'createdAt',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
|
|||||||
@ -15,7 +15,8 @@ const listAllowedFilters = [
|
|||||||
'deliveryTime',
|
'deliveryTime',
|
||||||
'cost',
|
'cost',
|
||||||
'costWithTax',
|
'costWithTax',
|
||||||
'marketplaces.marketplace',
|
'additionalCost',
|
||||||
|
'additionalCostWithTax',
|
||||||
'createdAt',
|
'createdAt',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
'_reference',
|
'_reference',
|
||||||
@ -25,8 +26,11 @@ const listAllowedSorters = [
|
|||||||
'courier',
|
'courier',
|
||||||
'active',
|
'active',
|
||||||
'tracked',
|
'tracked',
|
||||||
|
'deliveryTime',
|
||||||
'cost',
|
'cost',
|
||||||
'costWithTax',
|
'costWithTax',
|
||||||
|
'additionalCost',
|
||||||
|
'additionalCostWithTax',
|
||||||
'estimatedDeliveryTime',
|
'estimatedDeliveryTime',
|
||||||
'createdAt',
|
'createdAt',
|
||||||
'_id',
|
'_id',
|
||||||
@ -42,7 +46,8 @@ const propertiesAllowedFilters = [
|
|||||||
'deliveryTime',
|
'deliveryTime',
|
||||||
'cost',
|
'cost',
|
||||||
'costWithTax',
|
'costWithTax',
|
||||||
'marketplaces.marketplace',
|
'additionalCost',
|
||||||
|
'additionalCostWithTax',
|
||||||
];
|
];
|
||||||
import {
|
import {
|
||||||
listCourierServicesRouteHandler,
|
listCourierServicesRouteHandler,
|
||||||
|
|||||||
@ -11,11 +11,20 @@ const listAllowedFilters = [
|
|||||||
'active',
|
'active',
|
||||||
'isGlobal',
|
'isGlobal',
|
||||||
'state',
|
'state',
|
||||||
|
'connection.port',
|
||||||
'createdAt',
|
'createdAt',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
'_reference',
|
'_reference',
|
||||||
];
|
];
|
||||||
const listAllowedSorters = ['name', 'documentSize', 'connectedAt', 'updatedAt', 'state', 'createdAt'];
|
const listAllowedSorters = [
|
||||||
|
'name',
|
||||||
|
'documentSize',
|
||||||
|
'connectedAt',
|
||||||
|
'connection.port',
|
||||||
|
'updatedAt',
|
||||||
|
'state',
|
||||||
|
'createdAt',
|
||||||
|
];
|
||||||
const propertiesAllowedFilters = ['tags'];
|
const propertiesAllowedFilters = ['tags'];
|
||||||
import {
|
import {
|
||||||
listDocumentPrintersRouteHandler,
|
listDocumentPrintersRouteHandler,
|
||||||
|
|||||||
@ -11,7 +11,10 @@ const listAllowedFilters = [
|
|||||||
'material._id',
|
'material._id',
|
||||||
'diameter',
|
'diameter',
|
||||||
'name',
|
'name',
|
||||||
|
'density',
|
||||||
|
'emptySpoolWeight',
|
||||||
'cost',
|
'cost',
|
||||||
|
'costWithTax',
|
||||||
'createdAt',
|
'createdAt',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
'_reference',
|
'_reference',
|
||||||
@ -21,6 +24,9 @@ const listAllowedSorters = [
|
|||||||
'createdAt',
|
'createdAt',
|
||||||
'vendor',
|
'vendor',
|
||||||
'material',
|
'material',
|
||||||
|
'diameter',
|
||||||
|
'density',
|
||||||
|
'emptySpoolWeight',
|
||||||
'cost',
|
'cost',
|
||||||
'costWithTax',
|
'costWithTax',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
|
|||||||
@ -5,13 +5,26 @@ import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
|
|||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
const listAllowedFilters = ['product._id', '_id', 'name', 'createdAt', 'updatedAt', '_reference'];
|
const listAllowedFilters = [
|
||||||
|
'product._id',
|
||||||
|
'_id',
|
||||||
|
'name',
|
||||||
|
'cost',
|
||||||
|
'costWithTax',
|
||||||
|
'price',
|
||||||
|
'margin',
|
||||||
|
'priceWithTax',
|
||||||
|
'createdAt',
|
||||||
|
'updatedAt',
|
||||||
|
'_reference',
|
||||||
|
];
|
||||||
const listAllowedSorters = [
|
const listAllowedSorters = [
|
||||||
'name',
|
'name',
|
||||||
'priceMode',
|
'priceMode',
|
||||||
'cost',
|
'cost',
|
||||||
'costWithTax',
|
'costWithTax',
|
||||||
'price',
|
'price',
|
||||||
|
'margin',
|
||||||
'priceWithTax',
|
'priceWithTax',
|
||||||
'createdAt',
|
'createdAt',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
@ -59,24 +72,15 @@ router.get('/properties', checkPermissions('part', 'list'), isAuthenticated, asy
|
|||||||
listPartsByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
|
listPartsByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get(
|
router.get('/values', checkPermissions('part', 'list'), isAuthenticated, async (req, res) => {
|
||||||
'/values',
|
const { property } = req.query;
|
||||||
checkPermissions('part', 'list'),
|
const filter = await getFilter(req.query, listAllowedFilters, true);
|
||||||
isAuthenticated,
|
var masterFilter = {};
|
||||||
async (req, res) => {
|
if (req.query.masterFilter) {
|
||||||
const { property } = req.query;
|
masterFilter = await getFilter(JSON.parse(req.query.masterFilter), listAllowedFilters, true);
|
||||||
const filter = await getFilter(req.query, listAllowedFilters, true);
|
|
||||||
var masterFilter = {};
|
|
||||||
if (req.query.masterFilter) {
|
|
||||||
masterFilter = await getFilter(
|
|
||||||
JSON.parse(req.query.masterFilter),
|
|
||||||
listAllowedFilters,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
getPartPropertyValuesRouteHandler(req, res, property, filter, masterFilter);
|
|
||||||
}
|
}
|
||||||
);
|
getPartPropertyValuesRouteHandler(req, res, property, filter, masterFilter);
|
||||||
|
});
|
||||||
|
|
||||||
router.get('/search', checkPermissions('part', 'list'), isAuthenticated, async (req, res) => {
|
router.get('/search', checkPermissions('part', 'list'), isAuthenticated, async (req, res) => {
|
||||||
const { search } = req.query;
|
const { search } = req.query;
|
||||||
|
|||||||
@ -12,7 +12,10 @@ const listAllowedFilters = [
|
|||||||
'part._id',
|
'part._id',
|
||||||
'name',
|
'name',
|
||||||
'cost',
|
'cost',
|
||||||
|
'costWithTax',
|
||||||
'price',
|
'price',
|
||||||
|
'priceWithTax',
|
||||||
|
'margin',
|
||||||
'createdAt',
|
'createdAt',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
'_reference',
|
'_reference',
|
||||||
@ -25,6 +28,7 @@ const listAllowedSorters = [
|
|||||||
'costWithTax',
|
'costWithTax',
|
||||||
'price',
|
'price',
|
||||||
'priceWithTax',
|
'priceWithTax',
|
||||||
|
'margin',
|
||||||
'createdAt',
|
'createdAt',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
];
|
];
|
||||||
|
|||||||
@ -11,6 +11,11 @@ const listAllowedFilters = [
|
|||||||
'globalPrice',
|
'globalPrice',
|
||||||
'productCategory',
|
'productCategory',
|
||||||
'productCategory._id',
|
'productCategory._id',
|
||||||
|
'cost',
|
||||||
|
'costWithTax',
|
||||||
|
'price',
|
||||||
|
'margin',
|
||||||
|
'priceWithTax',
|
||||||
'createdAt',
|
'createdAt',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
'_reference',
|
'_reference',
|
||||||
@ -24,6 +29,7 @@ const listAllowedSorters = [
|
|||||||
'cost',
|
'cost',
|
||||||
'costWithTax',
|
'costWithTax',
|
||||||
'price',
|
'price',
|
||||||
|
'margin',
|
||||||
'priceWithTax',
|
'priceWithTax',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
];
|
];
|
||||||
|
|||||||
@ -12,7 +12,10 @@ const listAllowedFilters = [
|
|||||||
'product._id',
|
'product._id',
|
||||||
'name',
|
'name',
|
||||||
'cost',
|
'cost',
|
||||||
|
'costWithTax',
|
||||||
'price',
|
'price',
|
||||||
|
'priceWithTax',
|
||||||
|
'margin',
|
||||||
'createdAt',
|
'createdAt',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
'_reference',
|
'_reference',
|
||||||
@ -25,6 +28,7 @@ const listAllowedSorters = [
|
|||||||
'costWithTax',
|
'costWithTax',
|
||||||
'price',
|
'price',
|
||||||
'priceWithTax',
|
'priceWithTax',
|
||||||
|
'margin',
|
||||||
'createdAt',
|
'createdAt',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
];
|
];
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
|
|||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
const listAllowedFilters = ['name', 'createdAt', 'updatedAt', '_reference', 'tags'];
|
const listAllowedFilters = ['name', 'createdAt', 'updatedAt', '_reference', 'tags'];
|
||||||
const listAllowedSorters = ['name', 'createdAt', '_id', 'updatedAt', 'tags'];
|
const listAllowedSorters = ['name', 'createdAt', 'updatedAt'];
|
||||||
const propertiesAllowedFilters = ['tags'];
|
const propertiesAllowedFilters = ['tags'];
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
|||||||
@ -12,7 +12,6 @@ const listAllowedFilters = [
|
|||||||
'active',
|
'active',
|
||||||
'country',
|
'country',
|
||||||
'jurisdiction',
|
'jurisdiction',
|
||||||
'marketplaces.marketplace',
|
|
||||||
'createdAt',
|
'createdAt',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
'_reference',
|
'_reference',
|
||||||
|
|||||||
@ -21,12 +21,8 @@ const router = express.Router();
|
|||||||
const listAllowedFilters = [
|
const listAllowedFilters = [
|
||||||
'name',
|
'name',
|
||||||
'handlingTime',
|
'handlingTime',
|
||||||
'localPickup',
|
|
||||||
'globalShipping',
|
|
||||||
'freightShipping',
|
|
||||||
'pickupDropOff',
|
|
||||||
'courierServices',
|
'courierServices',
|
||||||
'marketplaces.marketplace',
|
'localPickup',
|
||||||
'createdAt',
|
'createdAt',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
'_reference',
|
'_reference',
|
||||||
@ -35,9 +31,8 @@ const listAllowedSorters = ['name', 'handlingTime', 'createdAt', '_id', 'updated
|
|||||||
const propertiesAllowedFilters = [
|
const propertiesAllowedFilters = [
|
||||||
'name',
|
'name',
|
||||||
'handlingTime',
|
'handlingTime',
|
||||||
'localPickup',
|
|
||||||
'courierServices',
|
'courierServices',
|
||||||
'marketplaces.marketplace',
|
'localPickup',
|
||||||
];
|
];
|
||||||
|
|
||||||
router.get('/', isAuthenticated, checkPermissions('fulfillmentPolicy', 'list'), async (req, res) => {
|
router.get('/', isAuthenticated, checkPermissions('fulfillmentPolicy', 'list'), async (req, res) => {
|
||||||
|
|||||||
@ -21,6 +21,7 @@ const listAllowedFilters = [
|
|||||||
'returnPolicy',
|
'returnPolicy',
|
||||||
'state',
|
'state',
|
||||||
'state.type',
|
'state.type',
|
||||||
|
'condition',
|
||||||
'createdAt',
|
'createdAt',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
'_reference',
|
'_reference',
|
||||||
@ -48,6 +49,7 @@ const propertiesAllowedFilters = [
|
|||||||
'returnPolicy',
|
'returnPolicy',
|
||||||
'state',
|
'state',
|
||||||
'state.type',
|
'state.type',
|
||||||
|
'condition',
|
||||||
'createdAt',
|
'createdAt',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
];
|
];
|
||||||
|
|||||||
@ -24,7 +24,6 @@ const listAllowedFilters = [
|
|||||||
'returnPeriodDays',
|
'returnPeriodDays',
|
||||||
'returnShippingCostPayer',
|
'returnShippingCostPayer',
|
||||||
'refundMethod',
|
'refundMethod',
|
||||||
'marketplaces.marketplace',
|
|
||||||
'createdAt',
|
'createdAt',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
'_reference',
|
'_reference',
|
||||||
@ -42,7 +41,6 @@ const propertiesAllowedFilters = [
|
|||||||
'returnsAccepted',
|
'returnsAccepted',
|
||||||
'returnShippingCostPayer',
|
'returnShippingCostPayer',
|
||||||
'refundMethod',
|
'refundMethod',
|
||||||
'marketplaces.marketplace',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
router.get('/', isAuthenticated, checkPermissions('returnPolicy', 'list'), async (req, res) => {
|
router.get('/', isAuthenticated, checkPermissions('returnPolicy', 'list'), async (req, res) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user