Some checks failed
farmcontrol/farmcontrol-api/pipeline/head There was a failure building this commit
This commit modifies the log level in the configuration file from "trace" to "debug" for improved logging clarity. It also introduces new routes for fulfillment, return, and payment policies in the index file, enhancing the marketplace integration capabilities. Additionally, the initialization process is updated to start the marketplace worker, ensuring that the application can handle marketplace operations effectively. Various schemas are updated to include new fields and relationships for policies, improving the overall functionality and flexibility of the marketplace management system.
121 lines
3.4 KiB
JavaScript
121 lines
3.4 KiB
JavaScript
import express from 'express';
|
|
import { isAuthenticated } from '../../keycloak.js';
|
|
import { checkPermissions } from '../../database/permissions.js';
|
|
import { getFilter, convertPropertiesString, getSort } from '../../utils.js';
|
|
import {
|
|
listPaymentPoliciesRouteHandler,
|
|
getPaymentPolicyRouteHandler,
|
|
editPaymentPolicyRouteHandler,
|
|
newPaymentPolicyRouteHandler,
|
|
deletePaymentPolicyRouteHandler,
|
|
listPaymentPoliciesByPropertiesRouteHandler,
|
|
getPaymentPolicyStatsRouteHandler,
|
|
getPaymentPolicyHistoryRouteHandler,
|
|
searchPaymentPoliciesRouteHandler,
|
|
getPaymentPolicyPropertyValuesRouteHandler,
|
|
getPaymentPolicyNeighborsRouteHandler,
|
|
} from '../../services/finance/paymentpolicies.js';
|
|
|
|
const router = express.Router();
|
|
|
|
const listAllowedFilters = [
|
|
'name',
|
|
'immediatePay',
|
|
'marketplaces.marketplace',
|
|
'createdAt',
|
|
'updatedAt',
|
|
'_reference',
|
|
];
|
|
const listAllowedSorters = ['name', 'immediatePay', 'createdAt', '_id', 'updatedAt'];
|
|
const propertiesAllowedFilters = ['name', 'immediatePay', 'marketplaces.marketplace'];
|
|
|
|
router.get('/', isAuthenticated, checkPermissions('paymentPolicy', 'list'), async (req, res) => {
|
|
const { page, limit, property, search, sortProperty, sortOrder } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
listPaymentPoliciesRouteHandler(
|
|
req,
|
|
res,
|
|
page,
|
|
limit,
|
|
property,
|
|
filter,
|
|
search,
|
|
getSort(sortProperty, listAllowedSorters),
|
|
sortOrder
|
|
);
|
|
});
|
|
|
|
router.get(
|
|
'/properties',
|
|
checkPermissions('paymentPolicy', 'list'),
|
|
isAuthenticated,
|
|
async (req, res) => {
|
|
const properties = convertPropertiesString(req.query.properties);
|
|
const filter = await getFilter(req.query, propertiesAllowedFilters, false);
|
|
let masterFilter = {};
|
|
if (req.query.masterFilter) {
|
|
masterFilter = JSON.parse(req.query.masterFilter);
|
|
}
|
|
listPaymentPoliciesByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
|
|
}
|
|
);
|
|
|
|
router.get(
|
|
'/values',
|
|
checkPermissions('paymentPolicy', 'list'),
|
|
isAuthenticated,
|
|
async (req, res) => {
|
|
getPaymentPolicyPropertyValuesRouteHandler(req, res, req.query.property);
|
|
}
|
|
);
|
|
|
|
router.get(
|
|
'/search',
|
|
checkPermissions('paymentPolicy', 'list'),
|
|
isAuthenticated,
|
|
async (req, res) => {
|
|
searchPaymentPoliciesRouteHandler(req, res, req.query.search);
|
|
}
|
|
);
|
|
|
|
router.post('/', isAuthenticated, checkPermissions('paymentPolicy', 'new'), async (req, res) => {
|
|
newPaymentPolicyRouteHandler(req, res);
|
|
});
|
|
|
|
router.get('/stats', isAuthenticated, async (req, res) => {
|
|
getPaymentPolicyStatsRouteHandler(req, res);
|
|
});
|
|
|
|
router.get('/history', isAuthenticated, async (req, res) => {
|
|
getPaymentPolicyHistoryRouteHandler(req, res);
|
|
});
|
|
|
|
router.get('/neighbors', isAuthenticated, async (req, res) => {
|
|
const { property, search, sortProperty, sortOrder, id } = req.query;
|
|
const filter = await getFilter(req.query, listAllowedFilters);
|
|
getPaymentPolicyNeighborsRouteHandler(
|
|
req,
|
|
res,
|
|
property,
|
|
filter,
|
|
search,
|
|
getSort(sortProperty, listAllowedSorters),
|
|
sortOrder,
|
|
id
|
|
);
|
|
});
|
|
|
|
router.get('/:id', isAuthenticated, async (req, res) => {
|
|
getPaymentPolicyRouteHandler(req, res);
|
|
});
|
|
|
|
router.put('/:id', isAuthenticated, checkPermissions('paymentPolicy', 'edit'), async (req, res) => {
|
|
editPaymentPolicyRouteHandler(req, res);
|
|
});
|
|
|
|
router.delete('/:id', isAuthenticated, async (req, res) => {
|
|
deletePaymentPolicyRouteHandler(req, res);
|
|
});
|
|
|
|
export default router;
|