All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good
This commit updates multiple route handlers across the management and inventory modules to replace the `sort` and `order` parameters with `sortProperty` and `sortOrder`. This change enhances consistency in query handling and improves the clarity of the code. Additionally, the `getFilter` function is modified to accommodate these new parameters, ensuring that filtering logic remains intact. Corresponding tests have been updated to verify the correct functionality of the modified routes.
96 lines
3.3 KiB
JavaScript
96 lines
3.3 KiB
JavaScript
import express from 'express';
|
|
import { isAuthenticated } from '../../keycloak.js';
|
|
import { checkPermissions } from '../../database/permissions.js';
|
|
import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
|
|
|
|
const router = express.Router();
|
|
|
|
const listAllowedFilters = [
|
|
'taxRate',
|
|
'taxRate._id',
|
|
'transactionType',
|
|
'transaction',
|
|
'transaction._id',
|
|
'transactionDate',
|
|
'createdAt',
|
|
'updatedAt',
|
|
'_reference',
|
|
];
|
|
const listAllowedSorters = ['transactionDate', 'amount', 'taxAmount', 'createdAt', '_id', 'updatedAt'];
|
|
const propertiesAllowedFilters = ['taxRate', 'transactionType', 'transaction'];
|
|
import {
|
|
listTaxRecordsRouteHandler,
|
|
getTaxRecordRouteHandler,
|
|
editTaxRecordRouteHandler,
|
|
newTaxRecordRouteHandler,
|
|
deleteTaxRecordRouteHandler,
|
|
listTaxRecordsByPropertiesRouteHandler,
|
|
getTaxRecordStatsRouteHandler,
|
|
getTaxRecordHistoryRouteHandler,
|
|
searchTaxRecordsRouteHandler,
|
|
getTaxRecordPropertyValuesRouteHandler,
|
|
|
|
getTaxRecordNeighborsRouteHandler
|
|
} from '../../services/finance/taxrecords.js';
|
|
|
|
// list of tax records
|
|
router.get('/', isAuthenticated, async (req, res) => {
|
|
const { page, limit, property, search, sortProperty, sortOrder } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
listTaxRecordsRouteHandler(req, res, page, limit, property, filter, search, getSort(sortProperty, listAllowedSorters), sortOrder);
|
|
});
|
|
|
|
router.get('/properties', checkPermissions('taxRecord', 'list'), 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);
|
|
}
|
|
listTaxRecordsByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
|
|
});
|
|
|
|
router.get('/values', checkPermissions('taxRecord', 'list'), isAuthenticated, async (req, res) => {
|
|
const { property } = req.query;
|
|
getTaxRecordPropertyValuesRouteHandler(req, res, property);
|
|
});
|
|
router.get('/search', checkPermissions('taxRecord', 'list'), isAuthenticated, async (req, res) => {
|
|
const { search } = req.query;
|
|
searchTaxRecordsRouteHandler(req, res, search);
|
|
});
|
|
|
|
|
|
router.post('/', isAuthenticated, checkPermissions('taxRecord', 'new'), async (req, res) => {
|
|
newTaxRecordRouteHandler(req, res);
|
|
});
|
|
|
|
// get tax record stats
|
|
router.get('/stats', isAuthenticated, async (req, res) => {
|
|
getTaxRecordStatsRouteHandler(req, res);
|
|
});
|
|
|
|
// get tax record history
|
|
router.get('/history', isAuthenticated, async (req, res) => {
|
|
getTaxRecordHistoryRouteHandler(req, res);
|
|
});
|
|
|
|
router.get('/neighbors', isAuthenticated, async (req, res) => {
|
|
const { property, search, sortProperty, sortOrder, id } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
getTaxRecordNeighborsRouteHandler(req, res, property, filter, search, getSort(sortProperty, listAllowedSorters), sortOrder, id);
|
|
});
|
|
|
|
router.get('/:id', isAuthenticated, checkPermissions('taxRecord', 'info'), async (req, res) => {
|
|
getTaxRecordRouteHandler(req, res);
|
|
});
|
|
|
|
router.put('/:id', isAuthenticated, checkPermissions('taxRecord', 'edit'), async (req, res) => {
|
|
editTaxRecordRouteHandler(req, res);
|
|
});
|
|
|
|
router.delete('/:id', isAuthenticated, async (req, res) => {
|
|
deleteTaxRecordRouteHandler(req, res);
|
|
});
|
|
|
|
export default router;
|