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', 'quantity', 'width', 'height', 'state', 'createdAt', 'updatedAt', '_reference', ]; const listAllowedSorters = ['name', 'quantity', 'state', 'createdAt', 'updatedAt']; const propertiesAllowedFilters = []; import { listDocumentJobsRouteHandler, getDocumentJobRouteHandler, editDocumentJobRouteHandler, newDocumentJobRouteHandler, deleteDocumentJobRouteHandler, listDocumentJobsByPropertiesRouteHandler, getDocumentJobStatsRouteHandler, getDocumentJobHistoryRouteHandler, searchDocumentJobsRouteHandler, getDocumentJobPropertyValuesRouteHandler, getDocumentJobNeighborsRouteHandler } from '../../services/management/documentjobs.js'; // list of document jobs router.get('/', isAuthenticated, checkPermissions('documentJob', 'list'), async (req, res) => { const { page, limit, property, search, sortProperty, sortOrder } = req.query; const filter = await getFilter(req.query, listAllowedFilters); listDocumentJobsRouteHandler(req, res, page, limit, property, filter, search, getSort(sortProperty, listAllowedSorters), sortOrder); }); router.get('/properties', checkPermissions('documentJob', '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); } listDocumentJobsByPropertiesRouteHandler(req, res, properties, filter, masterFilter); }); router.get('/values', checkPermissions('documentJob', 'list'), isAuthenticated, async (req, res) => { const { property } = req.query; getDocumentJobPropertyValuesRouteHandler(req, res, property); }); router.get('/search', checkPermissions('documentJob', 'list'), isAuthenticated, async (req, res) => { const { search } = req.query; searchDocumentJobsRouteHandler(req, res, search); }); router.post('/', isAuthenticated, checkPermissions('documentJob', 'new'), async (req, res) => { newDocumentJobRouteHandler(req, res); }); // get document job stats router.get('/stats', isAuthenticated, async (req, res) => { getDocumentJobStatsRouteHandler(req, res); }); // get documentjobs history router.get('/history', isAuthenticated, async (req, res) => { getDocumentJobHistoryRouteHandler(req, res); }); router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sortProperty, sortOrder, id } = req.query; const filter = await getFilter(req.query, listAllowedFilters); getDocumentJobNeighborsRouteHandler(req, res, property, filter, search, getSort(sortProperty, listAllowedSorters), sortOrder, id); }); router.get('/:id', isAuthenticated, async (req, res) => { getDocumentJobRouteHandler(req, res); }); router.put('/:id', isAuthenticated, checkPermissions('documentJob', 'edit'), async (req, res) => { editDocumentJobRouteHandler(req, res); }); router.delete('/:id', isAuthenticated, async (req, res) => { deleteDocumentJobRouteHandler(req, res); }); export default router;