All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good
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.
56 lines
1.3 KiB
JavaScript
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;
|