All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good
This update introduces a new utility function, `getSort`, to validate and apply sorting based on allowed sorters across multiple routes in the inventory and management modules. The function is integrated into route handlers for invoices, payments, tax records, filament stocks, order items, part stocks, product stocks, purchase orders, shipments, and various management entities. This enhancement improves the flexibility and consistency of sorting operations throughout the application.
90 lines
2.7 KiB
JavaScript
90 lines
2.7 KiB
JavaScript
import express from 'express';
|
|
import { isAuthenticated } from '../../keycloak.js';
|
|
import { convertPropertiesString, getFilter, getSort } from '../../utils.js';
|
|
|
|
const router = express.Router();
|
|
|
|
const listAllowedFilters = [
|
|
'name',
|
|
'username',
|
|
'firstName',
|
|
'lastName',
|
|
'email',
|
|
'createdAt',
|
|
'updatedAt',
|
|
'_reference',
|
|
];
|
|
const listAllowedSorters = ['name', 'email', 'role', 'createdAt', '_id', 'updatedAt'];
|
|
const propertiesAllowedFilters = [];
|
|
import {
|
|
listUsersRouteHandler,
|
|
listUsersByPropertiesRouteHandler,
|
|
getUserRouteHandler,
|
|
editUserRouteHandler,
|
|
getUserStatsRouteHandler,
|
|
getUserHistoryRouteHandler,
|
|
setAppPasswordRouteHandler,
|
|
searchUsersRouteHandler,
|
|
getUserPropertyValuesRouteHandler,
|
|
|
|
getUserNeighborsRouteHandler
|
|
} from '../../services/management/users.js';
|
|
|
|
// list of document templates
|
|
router.get('/', isAuthenticated, async (req, res) => {
|
|
const { page, limit, property, search, sort, order } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
listUsersRouteHandler(req, res, page, limit, property, filter, search, getSort(sort, listAllowedSorters), 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);
|
|
}
|
|
listUsersByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
|
|
});
|
|
|
|
router.get('/values', isAuthenticated, async (req, res) => {
|
|
const { property } = req.query;
|
|
getUserPropertyValuesRouteHandler(req, res, property);
|
|
});
|
|
router.get('/search', isAuthenticated, async (req, res) => {
|
|
const { search } = req.query;
|
|
searchUsersRouteHandler(req, res, search);
|
|
});
|
|
|
|
|
|
// get user stats
|
|
router.get('/stats', isAuthenticated, async (req, res) => {
|
|
getUserStatsRouteHandler(req, res);
|
|
});
|
|
|
|
// get user history
|
|
router.get('/history', isAuthenticated, async (req, res) => {
|
|
getUserHistoryRouteHandler(req, res);
|
|
});
|
|
|
|
router.get('/neighbors', isAuthenticated, async (req, res) => {
|
|
const { property, search, sort, order, id } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
getUserNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id);
|
|
});
|
|
|
|
router.get('/:id', isAuthenticated, async (req, res) => {
|
|
getUserRouteHandler(req, res);
|
|
});
|
|
|
|
// update user info
|
|
router.put('/:id', isAuthenticated, async (req, res) => {
|
|
editUserRouteHandler(req, res);
|
|
});
|
|
|
|
router.post('/:id/setAppPassword', isAuthenticated, async (req, res) => {
|
|
setAppPasswordRouteHandler(req, res);
|
|
});
|
|
|
|
export default router;
|