import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; import { getFilter, convertPropertiesString } from '../../utils.js'; const router = express.Router(); import { listStockLocationsRouteHandler, getStockLocationRouteHandler, editStockLocationRouteHandler, editMultipleStockLocationsRouteHandler, newStockLocationRouteHandler, deleteStockLocationRouteHandler, listStockLocationsByPropertiesRouteHandler, getStockLocationStatsRouteHandler, getStockLocationHistoryRouteHandler, } from '../../services/inventory/stocklocations.js'; router.get('/', isAuthenticated, (req, res) => { const { page, limit, property, search, sort, order } = req.query; const allowedFilters = ['name']; const filter = getFilter(req.query, allowedFilters); listStockLocationsRouteHandler(req, res, page, limit, property, filter, search, sort, order); }); router.get('/properties', isAuthenticated, (req, res) => { let properties = convertPropertiesString(req.query.properties); const allowedFilters = ['name']; const filter = getFilter(req.query, allowedFilters, false); var masterFilter = {}; if (req.query.masterFilter) { masterFilter = JSON.parse(req.query.masterFilter); } listStockLocationsByPropertiesRouteHandler(req, res, properties, filter, masterFilter); }); router.post('/', isAuthenticated, (req, res) => { newStockLocationRouteHandler(req, res); }); router.get('/stats', isAuthenticated, (req, res) => { getStockLocationStatsRouteHandler(req, res); }); router.get('/history', isAuthenticated, (req, res) => { getStockLocationHistoryRouteHandler(req, res); }); router.get('/:id', isAuthenticated, (req, res) => { getStockLocationRouteHandler(req, res); }); router.put('/', isAuthenticated, async (req, res) => { editMultipleStockLocationsRouteHandler(req, res); }); router.put('/:id', isAuthenticated, async (req, res) => { editStockLocationRouteHandler(req, res); }); router.delete('/:id', isAuthenticated, async (req, res) => { deleteStockLocationRouteHandler(req, res); }); export default router;