80 lines
2.6 KiB
JavaScript

import express from 'express';
import { isAuthenticated } from '../../keycloak.js';
const router = express.Router();
const listAllowedFilters = ['_id', 'name', 'filament', 'filament._id', 'filamentSku', 'filamentSku._id'];
const propertiesAllowedFilters = ['filament', 'filament._id', 'filamentSku', 'filamentSku._id'];
import {
listGCodeFilesRouteHandler,
editGCodeFileRouteHandler,
getGCodeFileRouteHandler,
newGCodeFileRouteHandler,
listGCodeFilesByPropertiesRouteHandler,
getGCodeFileContentRouteHandler,
getGCodeFileStatsRouteHandler,
searchGCodeFilesRouteHandler,
getGCodeFilePropertyValuesRouteHandler,
getGCodeFileNeighborsRouteHandler
} from '../../services/production/gcodefiles.js';
import { convertPropertiesString, getFilter } from '../../utils.js';
// list of gcodeFiles
router.get('/', isAuthenticated, (req, res) => {
const { page, limit, property, search, sort, order } = req.query;
const filter = getFilter(req.query, listAllowedFilters);
listGCodeFilesRouteHandler(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);
}
listGCodeFilesByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
});
router.get('/values', isAuthenticated, (req, res) => {
const { property } = req.query;
getGCodeFilePropertyValuesRouteHandler(req, res, property);
});
router.get('/search', isAuthenticated, (req, res) => {
const { search } = req.query;
searchGCodeFilesRouteHandler(req, res, search);
});
// create new gcodeFile
router.post('/', isAuthenticated, (req, res) => {
newGCodeFileRouteHandler(req, res);
});
// get gcodeFile stats
router.get('/stats', isAuthenticated, (req, res) => {
getGCodeFileStatsRouteHandler(req, res);
});
router.get('/neighbors', isAuthenticated, (req, res) => {
const { property, search, sort, order, id } = req.query;
const filter = getFilter(req.query, listAllowedFilters);
getGCodeFileNeighborsRouteHandler(req, res, property, filter, search, sort, order, id);
});
router.get('/:id', isAuthenticated, (req, res) => {
getGCodeFileRouteHandler(req, res);
});
router.get('/:id/content', isAuthenticated, (req, res) => {
getGCodeFileContentRouteHandler(req, res);
});
// update gcodeFile info
router.put('/:id', isAuthenticated, async (req, res) => {
editGCodeFileRouteHandler(req, res);
});
export default router;