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.
139 lines
3.7 KiB
JavaScript
139 lines
3.7 KiB
JavaScript
import express from 'express';
|
|
import { isAuthenticated } from '../../keycloak.js';
|
|
import { checkPermissions } from '../../database/permissions.js';
|
|
import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
|
|
|
|
const router = express.Router();
|
|
|
|
const listAllowedFilters = [
|
|
'_id',
|
|
'barcode',
|
|
'part',
|
|
'part._id',
|
|
'name',
|
|
'cost',
|
|
'overrideCost',
|
|
'costWithTax',
|
|
'price',
|
|
'overridePrice',
|
|
'priceWithTax',
|
|
'margin',
|
|
'createdAt',
|
|
'updatedAt',
|
|
'_reference',
|
|
];
|
|
const listAllowedSorters = [
|
|
'barcode',
|
|
'part',
|
|
'name',
|
|
'cost',
|
|
'costWithTax',
|
|
'price',
|
|
'priceWithTax',
|
|
'overrideCost',
|
|
'overridePrice',
|
|
'margin',
|
|
'createdAt',
|
|
'updatedAt',
|
|
];
|
|
const propertiesAllowedFilters = ['part', 'part._id'];
|
|
import {
|
|
listPartSkusRouteHandler,
|
|
getPartSkuRouteHandler,
|
|
editPartSkuRouteHandler,
|
|
newPartSkuRouteHandler,
|
|
deletePartSkuRouteHandler,
|
|
listPartSkusByPropertiesRouteHandler,
|
|
getPartSkuStatsRouteHandler,
|
|
getPartSkuHistoryRouteHandler,
|
|
searchPartSkusRouteHandler,
|
|
getPartSkuPropertyValuesRouteHandler,
|
|
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);
|
|
}
|
|
);
|
|
|
|
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);
|
|
});
|
|
|
|
router.get('/stats', isAuthenticated, async (req, res) => {
|
|
getPartSkuStatsRouteHandler(req, res);
|
|
});
|
|
|
|
router.get('/history', isAuthenticated, async (req, res) => {
|
|
getPartSkuHistoryRouteHandler(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
|
|
);
|
|
});
|
|
|
|
router.get('/:id', isAuthenticated, async (req, res) => {
|
|
getPartSkuRouteHandler(req, res);
|
|
});
|
|
|
|
router.put('/:id', isAuthenticated, checkPermissions('partSku', 'edit'), async (req, res) => {
|
|
editPartSkuRouteHandler(req, res);
|
|
});
|
|
|
|
router.delete('/:id', isAuthenticated, async (req, res) => {
|
|
deletePartSkuRouteHandler(req, res);
|
|
});
|
|
|
|
export default router;
|