Some checks failed
farmcontrol/farmcontrol-api/pipeline/head There was a failure building this commit
98 lines
3.0 KiB
JavaScript
98 lines
3.0 KiB
JavaScript
import express from 'express';
|
|
import { isAuthenticated } from '../../keycloak.js';
|
|
import { getFilter, convertPropertiesString } from '../../utils.js';
|
|
|
|
const router = express.Router();
|
|
|
|
const listAllowedFilters = [
|
|
'productSku',
|
|
'state',
|
|
'currentQuantity',
|
|
'productSku._id',
|
|
'stockLocation',
|
|
'stockLocation._id',
|
|
];
|
|
const propertiesAllowedFilters = ['productSku', 'state.type'];
|
|
import {
|
|
listProductStocksRouteHandler,
|
|
getProductStockRouteHandler,
|
|
editProductStockRouteHandler,
|
|
editMultipleProductStocksRouteHandler,
|
|
newProductStockRouteHandler,
|
|
deleteProductStockRouteHandler,
|
|
postProductStockRouteHandler,
|
|
listProductStocksByPropertiesRouteHandler,
|
|
getProductStockStatsRouteHandler,
|
|
getProductStockHistoryRouteHandler,
|
|
searchProductStocksRouteHandler,
|
|
getProductStockPropertyValuesRouteHandler,
|
|
|
|
getProductStockNeighborsRouteHandler
|
|
} from '../../services/inventory/productstocks.js';
|
|
|
|
router.get('/', isAuthenticated, (req, res) => {
|
|
const { page, limit, property, search, sort, order } = req.query;
|
|
const filter = getFilter(req.query, listAllowedFilters);
|
|
listProductStocksRouteHandler(req, res, page, limit, property, filter, search, sort, order);
|
|
});
|
|
|
|
router.get('/properties', isAuthenticated, (req, res) => {
|
|
let properties = convertPropertiesString(req.query.properties);
|
|
const filter = getFilter(req.query, propertiesAllowedFilters, false);
|
|
var masterFilter = {};
|
|
if (req.query.masterFilter) {
|
|
masterFilter = JSON.parse(req.query.masterFilter);
|
|
}
|
|
listProductStocksByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
|
|
});
|
|
|
|
router.get('/values', isAuthenticated, (req, res) => {
|
|
const { property } = req.query;
|
|
getProductStockPropertyValuesRouteHandler(req, res, property);
|
|
});
|
|
router.get('/search', isAuthenticated, (req, res) => {
|
|
const { search } = req.query;
|
|
searchProductStocksRouteHandler(req, res, search);
|
|
});
|
|
|
|
|
|
router.post('/', isAuthenticated, (req, res) => {
|
|
newProductStockRouteHandler(req, res);
|
|
});
|
|
|
|
router.get('/stats', isAuthenticated, (req, res) => {
|
|
getProductStockStatsRouteHandler(req, res);
|
|
});
|
|
|
|
router.get('/history', isAuthenticated, (req, res) => {
|
|
getProductStockHistoryRouteHandler(req, res);
|
|
});
|
|
|
|
router.get('/neighbors', isAuthenticated, (req, res) => {
|
|
const { property, search, sort, order, id } = req.query;
|
|
const filter = getFilter(req.query, listAllowedFilters);
|
|
getProductStockNeighborsRouteHandler(req, res, property, filter, search, sort, order, id);
|
|
});
|
|
|
|
router.get('/:id', isAuthenticated, (req, res) => {
|
|
getProductStockRouteHandler(req, res);
|
|
});
|
|
|
|
router.put('/', isAuthenticated, async (req, res) => {
|
|
editMultipleProductStocksRouteHandler(req, res);
|
|
});
|
|
|
|
router.put('/:id', isAuthenticated, async (req, res) => {
|
|
editProductStockRouteHandler(req, res);
|
|
});
|
|
|
|
router.delete('/:id', isAuthenticated, async (req, res) => {
|
|
deleteProductStockRouteHandler(req, res);
|
|
});
|
|
|
|
router.post('/:id/post', isAuthenticated, async (req, res) => {
|
|
postProductStockRouteHandler(req, res);
|
|
});
|
|
|
|
export default router;
|