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.
91 lines
2.7 KiB
JavaScript
91 lines
2.7 KiB
JavaScript
import express from 'express';
|
|
import { isAuthenticated } from '../../keycloak.js';
|
|
import {
|
|
listNotesRouteHandler,
|
|
getNoteRouteHandler,
|
|
editNoteRouteHandler,
|
|
newNoteRouteHandler,
|
|
deleteNoteRouteHandler,
|
|
listNotesByPropertiesRouteHandler,
|
|
getNoteStatsRouteHandler,
|
|
getNoteHistoryRouteHandler,
|
|
getNotePropertyValuesRouteHandler,
|
|
|
|
getNoteNeighborsRouteHandler
|
|
} from '../../services/misc/notes.js';
|
|
import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
|
|
|
|
const router = express.Router();
|
|
|
|
const listAllowedFilters = [
|
|
'_id',
|
|
'user',
|
|
'user._id',
|
|
'parentType',
|
|
'parent',
|
|
'parent._id',
|
|
'noteType',
|
|
'noteType._id',
|
|
'createdAt',
|
|
'updatedAt',
|
|
'_reference',
|
|
];
|
|
const listAllowedSorters = ['createdAt', 'updatedAt', 'parentType', 'noteType'];
|
|
const propertiesAllowedFilters = ['parent'];
|
|
|
|
// list of notes
|
|
router.get('/', isAuthenticated, async (req, res) => {
|
|
const { page, limit, property, search, sort, order } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
listNotesRouteHandler(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);
|
|
}
|
|
listNotesByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
|
|
});
|
|
|
|
router.get('/values', isAuthenticated, async (req, res) => {
|
|
const { property } = req.query;
|
|
getNotePropertyValuesRouteHandler(req, res, property);
|
|
});
|
|
|
|
// create new note
|
|
router.post('/', isAuthenticated, async (req, res) => {
|
|
newNoteRouteHandler(req, res);
|
|
});
|
|
|
|
// get note stats
|
|
router.get('/stats', isAuthenticated, async (req, res) => {
|
|
getNoteStatsRouteHandler(req, res);
|
|
});
|
|
|
|
// get note history
|
|
router.get('/history', isAuthenticated, async (req, res) => {
|
|
getNoteHistoryRouteHandler(req, res);
|
|
});
|
|
|
|
router.get('/neighbors', isAuthenticated, async (req, res) => {
|
|
const { property, search, sort, order, id } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
getNoteNeighborsRouteHandler(req, res, property, filter, search, getSort(sort, listAllowedSorters), order, id);
|
|
});
|
|
|
|
router.get('/:id', isAuthenticated, async (req, res) => {
|
|
getNoteRouteHandler(req, res);
|
|
});
|
|
|
|
// update note info
|
|
router.put('/:id', isAuthenticated, async (req, res) => {
|
|
editNoteRouteHandler(req, res);
|
|
});
|
|
// Delete note
|
|
router.delete('/:id', isAuthenticated, deleteNoteRouteHandler);
|
|
|
|
export default router;
|