import express from 'express'; import { isAuthenticated } from '../../keycloak.js'; import { getFilter, convertPropertiesString } from '../../utils.js'; const router = express.Router(); const listAllowedFilters = [ 'country', 'active', 'createdAt', 'updatedAt', 'name', '_reference' ]; const propertiesAllowedFilters = ['country', 'active', 'createdAt', 'updatedAt']; import { listVendorsRouteHandler, getVendorRouteHandler, editVendorRouteHandler, newVendorRouteHandler, deleteVendorRouteHandler, listVendorsByPropertiesRouteHandler, getVendorStatsRouteHandler, getVendorHistoryRouteHandler, searchVendorsRouteHandler, getVendorPropertyValuesRouteHandler, getVendorNeighborsRouteHandler } from '../../services/management/vendors.js'; // list of vendors router.get('/', isAuthenticated, async (req, res) => { const { page, limit, property, search, sort, order } = req.query; const filter = await getFilter(req.query, listAllowedFilters); listVendorsRouteHandler(req, res, page, limit, property, filter, search, sort, order); }); router.get('/properties', 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); } listVendorsByPropertiesRouteHandler(req, res, properties, filter, masterFilter); }); router.get('/values', isAuthenticated, async (req, res) => { const { property } = req.query; getVendorPropertyValuesRouteHandler(req, res, property); }); router.get('/search', isAuthenticated, async (req, res) => { const { search } = req.query; searchVendorsRouteHandler(req, res, search); }); router.post('/', isAuthenticated, async (req, res) => { newVendorRouteHandler(req, res); }); // get vendor stats router.get('/stats', isAuthenticated, async (req, res) => { getVendorStatsRouteHandler(req, res); }); // get vendors history router.get('/history', isAuthenticated, async (req, res) => { getVendorHistoryRouteHandler(req, res); }); router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sort, order, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); getVendorNeighborsRouteHandler(req, res, property, filter, search, sort, order, id); }); router.get('/:id', isAuthenticated, async (req, res) => { getVendorRouteHandler(req, res); }); router.put('/:id', isAuthenticated, async (req, res) => { editVendorRouteHandler(req, res); }); router.delete('/:id', isAuthenticated, async (req, res) => { deleteVendorRouteHandler(req, res); }); export default router;