Tom Butcher 5a4770820a
All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good
Refactor audit logs route and service for improved readability and maintainability
This update enhances the `auditlogs.js` files by formatting the allowed filters for better clarity and refactoring the `listAuditLogsRouteHandler` function to improve code readability. Unused filter translations for Mongoose have been removed, streamlining the filtering logic. These changes contribute to cleaner code and easier future modifications.
2026-08-19 17:08:13 +01:00

56 lines
1.3 KiB
JavaScript

import express from 'express';
import { isAuthenticated } from '../../keycloak.js';
import {
listAuditLogsRouteHandler,
getAuditLogRouteHandler,
getAuditLogStatsRouteHandler,
getAuditLogHistoryRouteHandler,
searchAuditLogsRouteHandler,
} from '../../services/management/auditlogs.js';
import { getFilter, getSort } from '../../utils.js';
const router = express.Router();
const listAllowedFilters = [
'parent._id',
'owner._id',
'operation',
'createdAt',
'updatedAt',
'_reference',
];
const listAllowedSorters = ['createdAt', 'updatedAt'];
router.get('/', isAuthenticated, async (req, res) => {
const { page, limit, sort, order } = req.query;
const filter = await getFilter(req.query, listAllowedFilters);
listAuditLogsRouteHandler(
req,
res,
page,
limit,
filter,
getSort(sort, listAllowedSorters),
order
);
});
router.get('/search', isAuthenticated, async (req, res) => {
const { search } = req.query;
searchAuditLogsRouteHandler(req, res, search);
});
router.get('/stats', isAuthenticated, async (req, res) => {
getAuditLogStatsRouteHandler(req, res);
});
router.get('/history', isAuthenticated, async (req, res) => {
getAuditLogHistoryRouteHandler(req, res);
});
router.get('/:id', async (req, res) => {
await getAuditLogRouteHandler(req, res);
});
export default router;