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.
90 lines
2.6 KiB
JavaScript
90 lines
2.6 KiB
JavaScript
import express from 'express';
|
|
import { isAuthenticated } from '../../keycloak.js';
|
|
|
|
const router = express.Router();
|
|
|
|
const listAllowedFilters = [
|
|
'state',
|
|
'gcodeFile._id',
|
|
'quantity',
|
|
'_id',
|
|
'_reference',
|
|
'createdAt',
|
|
'updatedAt'
|
|
];
|
|
const propertiesAllowedFilters = ['state'];
|
|
import {
|
|
listJobsRouteHandler,
|
|
listJobsByPropertiesRouteHandler,
|
|
getJobRouteHandler,
|
|
newJobRouteHandler,
|
|
deleteJobRouteHandler,
|
|
editJobRouteHandler,
|
|
getJobStatsRouteHandler,
|
|
getJobHistoryRouteHandler,
|
|
searchJobsRouteHandler,
|
|
getJobPropertyValuesRouteHandler,
|
|
getJobNeighborsRouteHandler,
|
|
} from '../../services/production/jobs.js';
|
|
import { convertPropertiesString, getFilter } from '../../utils.js';
|
|
|
|
// list of jobs
|
|
router.get('/', isAuthenticated, async (req, res) => {
|
|
const { page, limit, property, search, sort, order } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
listJobsRouteHandler(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);
|
|
}
|
|
listJobsByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
|
|
});
|
|
|
|
router.get('/values', isAuthenticated, async (req, res) => {
|
|
const { property } = req.query;
|
|
getJobPropertyValuesRouteHandler(req, res, property);
|
|
});
|
|
router.get('/search', isAuthenticated, async (req, res) => {
|
|
const { search } = req.query;
|
|
searchJobsRouteHandler(req, res, search);
|
|
});
|
|
|
|
router.post('/', isAuthenticated, async (req, res) => {
|
|
newJobRouteHandler(req, res);
|
|
});
|
|
|
|
// get job stats
|
|
router.get('/stats', isAuthenticated, async (req, res) => {
|
|
getJobStatsRouteHandler(req, res);
|
|
});
|
|
|
|
// get job history
|
|
router.get('/history', isAuthenticated, async (req, res) => {
|
|
getJobHistoryRouteHandler(req, res);
|
|
});
|
|
|
|
router.get('/neighbors', isAuthenticated, async (req, res) => {
|
|
const { property, search, sort, order, id } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
getJobNeighborsRouteHandler(req, res, property, filter, search, sort, order, id);
|
|
});
|
|
|
|
router.get('/:id', isAuthenticated, async (req, res) => {
|
|
getJobRouteHandler(req, res);
|
|
});
|
|
|
|
router.put('/:id', isAuthenticated, async (req, res) => {
|
|
editJobRouteHandler(req, res);
|
|
});
|
|
|
|
router.delete('/:id', isAuthenticated, async (req, res) => {
|
|
deleteJobRouteHandler(req, res);
|
|
});
|
|
|
|
export default router;
|