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 = ['name', 'createdAt', 'updatedAt', '_reference']; const listAllowedSorters = ['name', 'createdAt', 'updatedAt']; const propertiesAllowedFilters = ['name']; import { listStockLocationsRouteHandler, getStockLocationRouteHandler, editStockLocationRouteHandler, editMultipleStockLocationsRouteHandler, newStockLocationRouteHandler, deleteStockLocationRouteHandler, listStockLocationsByPropertiesRouteHandler, getStockLocationStatsRouteHandler, getStockLocationHistoryRouteHandler, searchStockLocationsRouteHandler, getStockLocationPropertyValuesRouteHandler, getStockLocationNeighborsRouteHandler } from '../../services/inventory/stocklocations.js'; router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sortProperty, sortOrder } = req.query; const filter = await getFilter(req.query, listAllowedFilters); listStockLocationsRouteHandler(req, res, page, limit, property, filter, search, getSort(sortProperty, listAllowedSorters), sortOrder); }); router.get('/properties', checkPermissions('stockLocation', '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); } listStockLocationsByPropertiesRouteHandler(req, res, properties, filter, masterFilter); }); router.get('/values', checkPermissions('stockLocation', 'list'), isAuthenticated, async (req, res) => { const { property } = req.query; getStockLocationPropertyValuesRouteHandler(req, res, property); }); router.get('/search', checkPermissions('stockLocation', 'list'), isAuthenticated, async (req, res) => { const { search } = req.query; searchStockLocationsRouteHandler(req, res, search); }); router.post('/', isAuthenticated, checkPermissions('stockLocation', 'new'), async (req, res) => { newStockLocationRouteHandler(req, res); }); router.get('/stats', isAuthenticated, async (req, res) => { getStockLocationStatsRouteHandler(req, res); }); router.get('/history', isAuthenticated, async (req, res) => { getStockLocationHistoryRouteHandler(req, res); }); router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sortProperty, sortOrder, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); getStockLocationNeighborsRouteHandler(req, res, property, filter, search, getSort(sortProperty, listAllowedSorters), sortOrder, id); }); router.get('/:id', isAuthenticated, checkPermissions('stockLocation', 'info'), async (req, res) => { getStockLocationRouteHandler(req, res); }); router.put('/', isAuthenticated, checkPermissions('stockLocation', 'edit'), async (req, res) => { editMultipleStockLocationsRouteHandler(req, res); }); router.put('/:id', isAuthenticated, checkPermissions('stockLocation', 'edit'), async (req, res) => { editStockLocationRouteHandler(req, res); }); router.delete('/:id', isAuthenticated, async (req, res) => { deleteStockLocationRouteHandler(req, res); }); export default router;