This update introduces several utility functions in `utils.js` to improve the handling of ObjectId paths, schema types, and filtering logic. Key additions include `isObjectIdPath`, `getBaseProperty`, and `getFilterFieldKind`, which enhance the flexibility of property handling. Additionally, all route handlers in the finance and inventory modules have been refactored to support asynchronous operations, ensuring better performance and responsiveness when processing requests.
89 lines
2.7 KiB
JavaScript
89 lines
2.7 KiB
JavaScript
import express from 'express';
|
|
import { isAuthenticated } from '../../keycloak.js';
|
|
|
|
const router = express.Router();
|
|
import {
|
|
listPrintersRouteHandler,
|
|
editPrinterRouteHandler,
|
|
getPrinterRouteHandler,
|
|
newPrinterRouteHandler,
|
|
getPrinterStatsRouteHandler,
|
|
listPrintersByPropertiesRouteHandler,
|
|
getPrinterHistoryRouteHandler,
|
|
searchPrintersRouteHandler,
|
|
getPrinterPropertyValuesRouteHandler,
|
|
getPrinterNeighborsRouteHandler,
|
|
} from '../../services/production/printers.js';
|
|
import { convertPropertiesString, getFilter } from '../../utils.js';
|
|
|
|
const listAllowedFilters = [
|
|
'tags',
|
|
'host._id',
|
|
'active',
|
|
'online',
|
|
'name',
|
|
'_id',
|
|
'_reference',
|
|
'state',
|
|
'createdAt',
|
|
'updatedAt'
|
|
];
|
|
const propertiesAllowedFilters = ['tags'];
|
|
// list of printers
|
|
router.get('/', isAuthenticated, async (req, res) => {
|
|
const { page, limit, property, search, sort, order } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
listPrintersRouteHandler(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);
|
|
}
|
|
listPrintersByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
|
|
});
|
|
|
|
router.get('/values', isAuthenticated, async (req, res) => {
|
|
const { property } = req.query;
|
|
getPrinterPropertyValuesRouteHandler(req, res, property);
|
|
});
|
|
router.get('/search', isAuthenticated, async (req, res) => {
|
|
const { search } = req.query;
|
|
searchPrintersRouteHandler(req, res, search);
|
|
});
|
|
|
|
// create new printer
|
|
router.post('/', isAuthenticated, async (req, res) => {
|
|
newPrinterRouteHandler(req, res);
|
|
});
|
|
|
|
// get printer history
|
|
router.get('/history', isAuthenticated, async (req, res) => {
|
|
getPrinterHistoryRouteHandler(req, res);
|
|
});
|
|
|
|
router.get('/neighbors', isAuthenticated, async (req, res) => {
|
|
const { property, search, sort, order, id } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
getPrinterNeighborsRouteHandler(req, res, property, filter, search, sort, order, id);
|
|
});
|
|
|
|
// get printer stats
|
|
router.get('/stats', isAuthenticated, async (req, res) => {
|
|
getPrinterStatsRouteHandler(req, res);
|
|
});
|
|
|
|
router.get('/:id', isAuthenticated, async (req, res) => {
|
|
getPrinterRouteHandler(req, res);
|
|
});
|
|
|
|
// update printer info
|
|
router.put('/:id', isAuthenticated, async (req, res) => {
|
|
editPrinterRouteHandler(req, res);
|
|
});
|
|
|
|
export default router;
|