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.
103 lines
2.9 KiB
JavaScript
103 lines
2.9 KiB
JavaScript
import express from 'express';
|
|
import { isAuthenticated } from '../../keycloak.js';
|
|
import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
|
|
|
|
const router = express.Router();
|
|
|
|
const listAllowedFilters = [
|
|
'_id',
|
|
'barcode',
|
|
'part',
|
|
'part._id',
|
|
'name',
|
|
'cost',
|
|
'price',
|
|
'createdAt',
|
|
'updatedAt',
|
|
'_reference',
|
|
];
|
|
const listAllowedSorters = [
|
|
'barcode',
|
|
'part',
|
|
'name',
|
|
'cost',
|
|
'costWithTax',
|
|
'price',
|
|
'priceWithTax',
|
|
'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, async (req, res) => {
|
|
const { page, limit, property, search, sort, order } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
listPartSkusRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), order);
|
|
});
|
|
|
|
router.get('/properties', 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', isAuthenticated, async (req, res) => {
|
|
const { property } = req.query;
|
|
getPartSkuPropertyValuesRouteHandler(req, res, property);
|
|
});
|
|
router.get('/search', isAuthenticated, async (req, res) => {
|
|
const { search } = req.query;
|
|
searchPartSkusRouteHandler(req, res, search);
|
|
});
|
|
|
|
|
|
router.post('/', isAuthenticated, 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, sort, order, id } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
getPartSkuNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id);
|
|
});
|
|
|
|
router.get('/:id', isAuthenticated, async (req, res) => {
|
|
getPartSkuRouteHandler(req, res);
|
|
});
|
|
|
|
router.put('/:id', isAuthenticated, async (req, res) => {
|
|
editPartSkuRouteHandler(req, res);
|
|
});
|
|
|
|
router.delete('/:id', isAuthenticated, async (req, res) => {
|
|
deletePartSkuRouteHandler(req, res);
|
|
});
|
|
|
|
export default router;
|