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.
94 lines
2.8 KiB
JavaScript
94 lines
2.8 KiB
JavaScript
import express from 'express';
|
|
import { isAuthenticated } from '../../keycloak.js';
|
|
import { getFilter, convertPropertiesString } from '../../utils.js';
|
|
|
|
const router = express.Router();
|
|
|
|
const listAllowedFilters = [
|
|
'name',
|
|
'website',
|
|
'email',
|
|
'phone',
|
|
'contact',
|
|
'country',
|
|
'createdAt',
|
|
'updatedAt',
|
|
'_reference'
|
|
];
|
|
const propertiesAllowedFilters = ['name', 'website', 'email', 'phone', 'contact', 'country'];
|
|
import {
|
|
listCouriersRouteHandler,
|
|
getCourierRouteHandler,
|
|
editCourierRouteHandler,
|
|
newCourierRouteHandler,
|
|
deleteCourierRouteHandler,
|
|
listCouriersByPropertiesRouteHandler,
|
|
getCourierStatsRouteHandler,
|
|
getCourierHistoryRouteHandler,
|
|
searchCouriersRouteHandler,
|
|
getCourierPropertyValuesRouteHandler,
|
|
|
|
getCourierNeighborsRouteHandler
|
|
} from '../../services/management/courier.js';
|
|
|
|
// list of couriers
|
|
router.get('/', isAuthenticated, async (req, res) => {
|
|
const { page, limit, property, search, sort, order } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
listCouriersRouteHandler(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);
|
|
}
|
|
listCouriersByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
|
|
});
|
|
|
|
router.get('/values', isAuthenticated, async (req, res) => {
|
|
const { property } = req.query;
|
|
getCourierPropertyValuesRouteHandler(req, res, property);
|
|
});
|
|
|
|
router.get('/search', isAuthenticated, async (req, res) => {
|
|
const { search } = req.query;
|
|
searchCouriersRouteHandler(req, res, search);
|
|
});
|
|
|
|
router.post('/', isAuthenticated, async (req, res) => {
|
|
newCourierRouteHandler(req, res);
|
|
});
|
|
|
|
// get courier stats
|
|
router.get('/stats', isAuthenticated, async (req, res) => {
|
|
getCourierStatsRouteHandler(req, res);
|
|
});
|
|
|
|
// get courier history
|
|
router.get('/history', isAuthenticated, async (req, res) => {
|
|
getCourierHistoryRouteHandler(req, res);
|
|
});
|
|
|
|
router.get('/neighbors', isAuthenticated, async (req, res) => {
|
|
const { property, search, sort, order, id } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
getCourierNeighborsRouteHandler(req, res, property, filter, search, sort, order, id);
|
|
});
|
|
|
|
router.get('/:id', isAuthenticated, async (req, res) => {
|
|
getCourierRouteHandler(req, res);
|
|
});
|
|
|
|
router.put('/:id', isAuthenticated, async (req, res) => {
|
|
editCourierRouteHandler(req, res);
|
|
});
|
|
|
|
router.delete('/:id', isAuthenticated, async (req, res) => {
|
|
deleteCourierRouteHandler(req, res);
|
|
});
|
|
|
|
export default router;
|