Enhance allowed filters and sorters in management routes to include 'overrideCost' and 'overridePrice'
This commit updates the allowed filters and sorters in the filament, part, and product SKU management routes to include 'overrideCost' and 'overridePrice'. Additionally, it refactors the route handlers for improved readability and consistency. These changes aim to enhance data retrieval capabilities and maintain a consistent structure across the management routes.
This commit is contained in:
parent
91eb22ac49
commit
9f5b390771
@ -13,6 +13,7 @@ const listAllowedFilters = [
|
||||
'name',
|
||||
'color',
|
||||
'cost',
|
||||
'overrideCost',
|
||||
'costWithTax',
|
||||
'createdAt',
|
||||
'updatedAt',
|
||||
@ -25,6 +26,7 @@ const listAllowedSorters = [
|
||||
'color',
|
||||
'cost',
|
||||
'costWithTax',
|
||||
'overrideCost',
|
||||
'createdAt',
|
||||
'updatedAt',
|
||||
];
|
||||
@ -46,18 +48,33 @@ import {
|
||||
router.get('/', isAuthenticated, checkPermissions('filamentSku', 'list'), async (req, res) => {
|
||||
const { page, limit, property, search, sortProperty, sortOrder } = req.query;
|
||||
const filter = await getFilter(req.query, listAllowedFilters);
|
||||
listFilamentSkusRouteHandler(req, res, page, limit, property, filter, search, getSort(sortProperty, listAllowedSorters), sortOrder);
|
||||
listFilamentSkusRouteHandler(
|
||||
req,
|
||||
res,
|
||||
page,
|
||||
limit,
|
||||
property,
|
||||
filter,
|
||||
search,
|
||||
getSort(sortProperty, listAllowedSorters),
|
||||
sortOrder
|
||||
);
|
||||
});
|
||||
|
||||
router.get('/properties', checkPermissions('filamentSku', 'list'), isAuthenticated, async (req, res) => {
|
||||
let properties = convertPropertiesString(req.query.properties);
|
||||
const filter = await getFilter(req.query, propertiesAllowedFilters, false);
|
||||
let masterFilter = {};
|
||||
if (req.query.masterFilter) {
|
||||
masterFilter = JSON.parse(req.query.masterFilter);
|
||||
router.get(
|
||||
'/properties',
|
||||
checkPermissions('filamentSku', 'list'),
|
||||
isAuthenticated,
|
||||
async (req, res) => {
|
||||
let properties = convertPropertiesString(req.query.properties);
|
||||
const filter = await getFilter(req.query, propertiesAllowedFilters, false);
|
||||
let masterFilter = {};
|
||||
if (req.query.masterFilter) {
|
||||
masterFilter = JSON.parse(req.query.masterFilter);
|
||||
}
|
||||
listFilamentSkusByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
|
||||
}
|
||||
listFilamentSkusByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
|
||||
});
|
||||
);
|
||||
|
||||
router.get(
|
||||
'/values',
|
||||
@ -68,23 +85,29 @@ router.get(
|
||||
const filter = await getFilter(req.query, listAllowedFilters, true);
|
||||
var masterFilter = {};
|
||||
if (req.query.masterFilter) {
|
||||
masterFilter = await getFilter(
|
||||
JSON.parse(req.query.masterFilter),
|
||||
listAllowedFilters,
|
||||
true
|
||||
);
|
||||
masterFilter = await getFilter(JSON.parse(req.query.masterFilter), listAllowedFilters, true);
|
||||
}
|
||||
getFilamentSkuPropertyValuesRouteHandler(req, res, property, filter, masterFilter);
|
||||
}
|
||||
);
|
||||
router.get('/search', checkPermissions('filamentSku', 'list'), isAuthenticated, async (req, res) => {
|
||||
const { search } = req.query;
|
||||
searchFilamentSkusRouteHandler(req, res, search);
|
||||
});
|
||||
router.get(
|
||||
'/search',
|
||||
checkPermissions('filamentSku', 'list'),
|
||||
isAuthenticated,
|
||||
async (req, res) => {
|
||||
const { search } = req.query;
|
||||
searchFilamentSkusRouteHandler(req, res, search);
|
||||
}
|
||||
);
|
||||
|
||||
router.post('/', isAuthenticated, checkPermissions('filament', 'newFilamentSku'), async (req, res) => {
|
||||
newFilamentSkuRouteHandler(req, res);
|
||||
});
|
||||
router.post(
|
||||
'/',
|
||||
isAuthenticated,
|
||||
checkPermissions('filament', 'newFilamentSku'),
|
||||
async (req, res) => {
|
||||
newFilamentSkuRouteHandler(req, res);
|
||||
}
|
||||
);
|
||||
|
||||
router.get('/stats', isAuthenticated, async (req, res) => {
|
||||
getFilamentSkuStatsRouteHandler(req, res);
|
||||
@ -97,7 +120,16 @@ router.get('/history', isAuthenticated, async (req, res) => {
|
||||
router.get('/neighbors', isAuthenticated, async (req, res) => {
|
||||
const { property, search, sortProperty, sortOrder, id } = req.query;
|
||||
const filter = await getFilter(req.query, listAllowedFilters);
|
||||
getFilamentSkuNeighborsRouteHandler(req, res, property, filter, search, getSort(sortProperty, listAllowedSorters), sortOrder, id);
|
||||
getFilamentSkuNeighborsRouteHandler(
|
||||
req,
|
||||
res,
|
||||
property,
|
||||
filter,
|
||||
search,
|
||||
getSort(sortProperty, listAllowedSorters),
|
||||
sortOrder,
|
||||
id
|
||||
);
|
||||
});
|
||||
|
||||
router.get('/:id', isAuthenticated, async (req, res) => {
|
||||
|
||||
@ -12,8 +12,10 @@ const listAllowedFilters = [
|
||||
'part._id',
|
||||
'name',
|
||||
'cost',
|
||||
'overrideCost',
|
||||
'costWithTax',
|
||||
'price',
|
||||
'overridePrice',
|
||||
'priceWithTax',
|
||||
'margin',
|
||||
'createdAt',
|
||||
@ -28,6 +30,8 @@ const listAllowedSorters = [
|
||||
'costWithTax',
|
||||
'price',
|
||||
'priceWithTax',
|
||||
'overrideCost',
|
||||
'overridePrice',
|
||||
'margin',
|
||||
'createdAt',
|
||||
'updatedAt',
|
||||
@ -44,50 +48,54 @@ import {
|
||||
getPartSkuHistoryRouteHandler,
|
||||
searchPartSkusRouteHandler,
|
||||
getPartSkuPropertyValuesRouteHandler,
|
||||
|
||||
getPartSkuNeighborsRouteHandler
|
||||
getPartSkuNeighborsRouteHandler,
|
||||
} from '../../services/management/partskus.js';
|
||||
|
||||
router.get('/', isAuthenticated, checkPermissions('partSku', 'list'), async (req, res) => {
|
||||
const { page, limit, property, search, sortProperty, sortOrder } = req.query;
|
||||
const filter = await getFilter(req.query, listAllowedFilters);
|
||||
listPartSkusRouteHandler(req, res, page, limit, property, filter, search, getSort(sortProperty, listAllowedSorters), sortOrder);
|
||||
});
|
||||
|
||||
router.get('/properties', checkPermissions('partSku', 'list'), isAuthenticated, async (req, res) => {
|
||||
let properties = convertPropertiesString(req.query.properties);
|
||||
const filter = await getFilter(req.query, propertiesAllowedFilters, false);
|
||||
let masterFilter = {};
|
||||
if (req.query.masterFilter) {
|
||||
masterFilter = JSON.parse(req.query.masterFilter);
|
||||
}
|
||||
listPartSkusByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
|
||||
const filter = await getFilter(req.query, listAllowedFilters);
|
||||
listPartSkusRouteHandler(
|
||||
req,
|
||||
res,
|
||||
page,
|
||||
limit,
|
||||
property,
|
||||
filter,
|
||||
search,
|
||||
getSort(sortProperty, listAllowedSorters),
|
||||
sortOrder
|
||||
);
|
||||
});
|
||||
|
||||
router.get(
|
||||
'/values',
|
||||
'/properties',
|
||||
checkPermissions('partSku', 'list'),
|
||||
isAuthenticated,
|
||||
async (req, res) => {
|
||||
const { property } = req.query;
|
||||
const filter = await getFilter(req.query, listAllowedFilters, true);
|
||||
var masterFilter = {};
|
||||
let properties = convertPropertiesString(req.query.properties);
|
||||
const filter = await getFilter(req.query, propertiesAllowedFilters, false);
|
||||
let masterFilter = {};
|
||||
if (req.query.masterFilter) {
|
||||
masterFilter = await getFilter(
|
||||
JSON.parse(req.query.masterFilter),
|
||||
listAllowedFilters,
|
||||
true
|
||||
);
|
||||
masterFilter = JSON.parse(req.query.masterFilter);
|
||||
}
|
||||
getPartSkuPropertyValuesRouteHandler(req, res, property, filter, masterFilter);
|
||||
listPartSkusByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
|
||||
}
|
||||
);
|
||||
|
||||
router.get('/values', checkPermissions('partSku', 'list'), isAuthenticated, async (req, res) => {
|
||||
const { property } = req.query;
|
||||
const filter = await getFilter(req.query, listAllowedFilters, true);
|
||||
var masterFilter = {};
|
||||
if (req.query.masterFilter) {
|
||||
masterFilter = await getFilter(JSON.parse(req.query.masterFilter), listAllowedFilters, true);
|
||||
}
|
||||
getPartSkuPropertyValuesRouteHandler(req, res, property, filter, masterFilter);
|
||||
});
|
||||
router.get('/search', checkPermissions('partSku', 'list'), isAuthenticated, async (req, res) => {
|
||||
const { search } = req.query;
|
||||
searchPartSkusRouteHandler(req, res, search);
|
||||
});
|
||||
|
||||
|
||||
router.post('/', isAuthenticated, checkPermissions('part', 'newPartSku'), async (req, res) => {
|
||||
newPartSkuRouteHandler(req, res);
|
||||
});
|
||||
@ -103,7 +111,16 @@ router.get('/history', isAuthenticated, async (req, res) => {
|
||||
router.get('/neighbors', isAuthenticated, async (req, res) => {
|
||||
const { property, search, sortProperty, sortOrder, id } = req.query;
|
||||
const filter = await getFilter(req.query, listAllowedFilters);
|
||||
getPartSkuNeighborsRouteHandler(req, res, property, filter, search, getSort(sortProperty, listAllowedSorters), sortOrder, id);
|
||||
getPartSkuNeighborsRouteHandler(
|
||||
req,
|
||||
res,
|
||||
property,
|
||||
filter,
|
||||
search,
|
||||
getSort(sortProperty, listAllowedSorters),
|
||||
sortOrder,
|
||||
id
|
||||
);
|
||||
});
|
||||
|
||||
router.get('/:id', isAuthenticated, async (req, res) => {
|
||||
|
||||
@ -12,6 +12,8 @@ const listAllowedFilters = [
|
||||
'product._id',
|
||||
'name',
|
||||
'cost',
|
||||
'overrideCost',
|
||||
'overridePrice',
|
||||
'costWithTax',
|
||||
'price',
|
||||
'priceWithTax',
|
||||
@ -26,6 +28,8 @@ const listAllowedSorters = [
|
||||
'name',
|
||||
'cost',
|
||||
'costWithTax',
|
||||
'overrideCost',
|
||||
'overridePrice',
|
||||
'price',
|
||||
'priceWithTax',
|
||||
'margin',
|
||||
@ -44,53 +48,62 @@ import {
|
||||
getProductSkuHistoryRouteHandler,
|
||||
searchProductSkusRouteHandler,
|
||||
getProductSkuPropertyValuesRouteHandler,
|
||||
|
||||
getProductSkuNeighborsRouteHandler
|
||||
getProductSkuNeighborsRouteHandler,
|
||||
} from '../../services/management/productskus.js';
|
||||
|
||||
router.get('/', isAuthenticated, checkPermissions('productSku', 'list'), async (req, res) => {
|
||||
const { page, limit, property, search, sortProperty, sortOrder } = req.query;
|
||||
const filter = await getFilter(req.query, listAllowedFilters);
|
||||
listProductSkusRouteHandler(req, res, page, limit, property, filter, search, getSort(sortProperty, listAllowedSorters), sortOrder);
|
||||
});
|
||||
|
||||
router.get('/properties', checkPermissions('productSku', 'list'), isAuthenticated, async (req, res) => {
|
||||
let properties = convertPropertiesString(req.query.properties);
|
||||
const filter = await getFilter(req.query, propertiesAllowedFilters, false);
|
||||
let masterFilter = {};
|
||||
if (req.query.masterFilter) {
|
||||
masterFilter = JSON.parse(req.query.masterFilter);
|
||||
}
|
||||
listProductSkusByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
|
||||
const filter = await getFilter(req.query, listAllowedFilters);
|
||||
listProductSkusRouteHandler(
|
||||
req,
|
||||
res,
|
||||
page,
|
||||
limit,
|
||||
property,
|
||||
filter,
|
||||
search,
|
||||
getSort(sortProperty, listAllowedSorters),
|
||||
sortOrder
|
||||
);
|
||||
});
|
||||
|
||||
router.get(
|
||||
'/values',
|
||||
'/properties',
|
||||
checkPermissions('productSku', 'list'),
|
||||
isAuthenticated,
|
||||
async (req, res) => {
|
||||
const { property } = req.query;
|
||||
const filter = await getFilter(req.query, listAllowedFilters, true);
|
||||
var masterFilter = {};
|
||||
let properties = convertPropertiesString(req.query.properties);
|
||||
const filter = await getFilter(req.query, propertiesAllowedFilters, false);
|
||||
let masterFilter = {};
|
||||
if (req.query.masterFilter) {
|
||||
masterFilter = await getFilter(
|
||||
JSON.parse(req.query.masterFilter),
|
||||
listAllowedFilters,
|
||||
true
|
||||
);
|
||||
masterFilter = JSON.parse(req.query.masterFilter);
|
||||
}
|
||||
getProductSkuPropertyValuesRouteHandler(req, res, property, filter, masterFilter);
|
||||
listProductSkusByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
|
||||
}
|
||||
);
|
||||
|
||||
router.get('/values', checkPermissions('productSku', 'list'), isAuthenticated, async (req, res) => {
|
||||
const { property } = req.query;
|
||||
const filter = await getFilter(req.query, listAllowedFilters, true);
|
||||
var masterFilter = {};
|
||||
if (req.query.masterFilter) {
|
||||
masterFilter = await getFilter(JSON.parse(req.query.masterFilter), listAllowedFilters, true);
|
||||
}
|
||||
getProductSkuPropertyValuesRouteHandler(req, res, property, filter, masterFilter);
|
||||
});
|
||||
router.get('/search', checkPermissions('productSku', 'list'), isAuthenticated, async (req, res) => {
|
||||
const { search } = req.query;
|
||||
searchProductSkusRouteHandler(req, res, search);
|
||||
});
|
||||
|
||||
|
||||
router.post('/', isAuthenticated, checkPermissions('product', 'newProductSku'), async (req, res) => {
|
||||
newProductSkuRouteHandler(req, res);
|
||||
});
|
||||
router.post(
|
||||
'/',
|
||||
isAuthenticated,
|
||||
checkPermissions('product', 'newProductSku'),
|
||||
async (req, res) => {
|
||||
newProductSkuRouteHandler(req, res);
|
||||
}
|
||||
);
|
||||
|
||||
router.get('/stats', isAuthenticated, async (req, res) => {
|
||||
getProductSkuStatsRouteHandler(req, res);
|
||||
@ -103,7 +116,16 @@ router.get('/history', isAuthenticated, async (req, res) => {
|
||||
router.get('/neighbors', isAuthenticated, async (req, res) => {
|
||||
const { property, search, sortProperty, sortOrder, id } = req.query;
|
||||
const filter = await getFilter(req.query, listAllowedFilters);
|
||||
getProductSkuNeighborsRouteHandler(req, res, property, filter, search, getSort(sortProperty, listAllowedSorters), sortOrder, id);
|
||||
getProductSkuNeighborsRouteHandler(
|
||||
req,
|
||||
res,
|
||||
property,
|
||||
filter,
|
||||
search,
|
||||
getSort(sortProperty, listAllowedSorters),
|
||||
sortOrder,
|
||||
id
|
||||
);
|
||||
});
|
||||
|
||||
router.get('/:id', isAuthenticated, async (req, res) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user