All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good
This commit updates multiple route handlers across the management and inventory modules to replace the `sort` and `order` parameters with `sortProperty` and `sortOrder`. This change enhances consistency in query handling and improves the clarity of the code. Additionally, the `getFilter` function is modified to accommodate these new parameters, ensuring that filtering logic remains intact. Corresponding tests have been updated to verify the correct functionality of the modified routes.
103 lines
3.6 KiB
JavaScript
103 lines
3.6 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 = [
|
|
'partSku',
|
|
'partSku._id',
|
|
'state',
|
|
'startingQuantity',
|
|
'currentQuantity',
|
|
'stockLocation',
|
|
'stockLocation._id',
|
|
'createdAt',
|
|
'updatedAt',
|
|
'_reference',
|
|
];
|
|
const listAllowedSorters = ['partSku', 'startingQuantity', 'currentQuantity', 'state', 'createdAt', 'updatedAt'];
|
|
const propertiesAllowedFilters = ['part', 'state.type'];
|
|
import {
|
|
listPartStocksRouteHandler,
|
|
getPartStockRouteHandler,
|
|
editPartStockRouteHandler,
|
|
editMultiplePartStocksRouteHandler,
|
|
newPartStockRouteHandler,
|
|
deletePartStockRouteHandler,
|
|
listPartStocksByPropertiesRouteHandler,
|
|
getPartStockStatsRouteHandler,
|
|
getPartStockHistoryRouteHandler,
|
|
searchPartStocksRouteHandler,
|
|
getPartStockPropertyValuesRouteHandler,
|
|
|
|
getPartStockNeighborsRouteHandler
|
|
} from '../../services/inventory/partstocks.js';
|
|
|
|
// list of part stocks
|
|
router.get('/', isAuthenticated, async (req, res) => {
|
|
const { page, limit, property, search, sortProperty, sortOrder } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
listPartStocksRouteHandler(req, res, page, limit, property, filter, search, getSort(sortProperty, listAllowedSorters), sortOrder);
|
|
});
|
|
|
|
router.get('/properties', checkPermissions('partStock', 'list'), isAuthenticated, async (req, res) => {
|
|
let properties = convertPropertiesString(req.query.properties);
|
|
const filter = await getFilter(req.query, propertiesAllowedFilters, false);
|
|
var masterFilter = {};
|
|
if (req.query.masterFilter) {
|
|
masterFilter = JSON.parse(req.query.masterFilter);
|
|
}
|
|
listPartStocksByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
|
|
});
|
|
|
|
router.get('/values', checkPermissions('partStock', 'list'), isAuthenticated, async (req, res) => {
|
|
const { property } = req.query;
|
|
getPartStockPropertyValuesRouteHandler(req, res, property);
|
|
});
|
|
router.get('/search', checkPermissions('partStock', 'list'), isAuthenticated, async (req, res) => {
|
|
const { search } = req.query;
|
|
searchPartStocksRouteHandler(req, res, search);
|
|
});
|
|
|
|
|
|
router.post('/', isAuthenticated, checkPermissions('partStock', 'new'), async (req, res) => {
|
|
newPartStockRouteHandler(req, res);
|
|
});
|
|
|
|
// get part stock stats
|
|
router.get('/stats', isAuthenticated, async (req, res) => {
|
|
getPartStockStatsRouteHandler(req, res);
|
|
});
|
|
|
|
// get part stock history
|
|
router.get('/history', isAuthenticated, async (req, res) => {
|
|
getPartStockHistoryRouteHandler(req, res);
|
|
});
|
|
|
|
router.get('/neighbors', isAuthenticated, async (req, res) => {
|
|
const { property, search, sortProperty, sortOrder, id } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
getPartStockNeighborsRouteHandler(req, res, property, filter, search, getSort(sortProperty, listAllowedSorters), sortOrder, id);
|
|
});
|
|
|
|
router.get('/:id', isAuthenticated, checkPermissions('partStock', 'info'), async (req, res) => {
|
|
getPartStockRouteHandler(req, res);
|
|
});
|
|
|
|
// update multiple part stocks
|
|
router.put('/', isAuthenticated, checkPermissions('partStock', 'edit'), async (req, res) => {
|
|
editMultiplePartStocksRouteHandler(req, res);
|
|
});
|
|
|
|
router.put('/:id', isAuthenticated, checkPermissions('partStock', 'edit'), async (req, res) => {
|
|
editPartStockRouteHandler(req, res);
|
|
});
|
|
|
|
router.delete('/:id', isAuthenticated, async (req, res) => {
|
|
deletePartStockRouteHandler(req, res);
|
|
});
|
|
|
|
export default router;
|