Enhance file management routes by adding 'extension' to allowed sorters and improving code readability
All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good

This commit updates the list of allowed sorters in the file management routes to include 'extension', enhancing sorting capabilities. Additionally, it refactors the route handlers for better readability by formatting the function calls across multiple lines. These changes improve the maintainability of the code while ensuring consistent functionality in file management operations.
This commit is contained in:
Tom Butcher 2026-09-14 10:30:10 +01:00
parent 52162e1ec6
commit 9fe854e37b

View File

@ -15,7 +15,7 @@ const listAllowedFilters = [
'updatedAt', 'updatedAt',
'_reference', '_reference',
]; ];
const listAllowedSorters = ['name', 'type', 'size', 'createdAt', 'temp', 'updatedAt']; const listAllowedSorters = ['name', 'type', 'size', 'createdAt', 'temp', 'updatedAt', 'extension'];
const propertiesAllowedFilters = ['type', 'extension']; const propertiesAllowedFilters = ['type', 'extension'];
import { import {
listFilesRouteHandler, listFilesRouteHandler,
@ -32,15 +32,24 @@ import {
getFileHistoryRouteHandler, getFileHistoryRouteHandler,
searchFilesRouteHandler, searchFilesRouteHandler,
getFilePropertyValuesRouteHandler, getFilePropertyValuesRouteHandler,
getFileNeighborsRouteHandler,
getFileNeighborsRouteHandler
} from '../../services/management/files.js'; } from '../../services/management/files.js';
// list of files // list of files
router.get('/', isAuthenticated, checkPermissions('file', 'list'), async (req, res) => { router.get('/', isAuthenticated, checkPermissions('file', 'list'), async (req, res) => {
const { page, limit, property, search, sortProperty, sortOrder } = req.query; const { page, limit, property, search, sortProperty, sortOrder } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); const filter = await getFilter(req.query, listAllowedFilters);
listFilesRouteHandler(req, res, page, limit, property, filter, search, getSort(sortProperty, listAllowedSorters), sortOrder); listFilesRouteHandler(
req,
res,
page,
limit,
property,
filter,
search,
getSort(sortProperty, listAllowedSorters),
sortOrder
);
}); });
router.get('/properties', checkPermissions('file', 'list'), isAuthenticated, async (req, res) => { router.get('/properties', checkPermissions('file', 'list'), isAuthenticated, async (req, res) => {
@ -53,24 +62,15 @@ router.get('/properties', checkPermissions('file', 'list'), isAuthenticated, asy
listFilesByPropertiesRouteHandler(req, res, properties, filter, masterFilter); listFilesByPropertiesRouteHandler(req, res, properties, filter, masterFilter);
}); });
router.get( router.get('/values', checkPermissions('file', 'list'), isAuthenticated, async (req, res) => {
'/values', const { property } = req.query;
checkPermissions('file', 'list'), const filter = await getFilter(req.query, listAllowedFilters, true);
isAuthenticated, var masterFilter = {};
async (req, res) => { if (req.query.masterFilter) {
const { property } = req.query; masterFilter = await getFilter(JSON.parse(req.query.masterFilter), listAllowedFilters, true);
const filter = await getFilter(req.query, listAllowedFilters, true);
var masterFilter = {};
if (req.query.masterFilter) {
masterFilter = await getFilter(
JSON.parse(req.query.masterFilter),
listAllowedFilters,
true
);
}
getFilePropertyValuesRouteHandler(req, res, property, filter, masterFilter);
} }
); getFilePropertyValuesRouteHandler(req, res, property, filter, masterFilter);
});
router.get('/search', checkPermissions('file', 'list'), isAuthenticated, async (req, res) => { router.get('/search', checkPermissions('file', 'list'), isAuthenticated, async (req, res) => {
const { search } = req.query; const { search } = req.query;
@ -98,7 +98,16 @@ router.delete('/:id/flush', isAuthenticated, async (req, res) => {
router.get('/neighbors', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => {
const { property, search, sortProperty, sortOrder, id } = req.query; const { property, search, sortProperty, sortOrder, id } = req.query;
const filter = await getFilter(req.query, listAllowedFilters); const filter = await getFilter(req.query, listAllowedFilters);
getFileNeighborsRouteHandler(req, res, property, filter, search, getSort(sortProperty, listAllowedSorters), sortOrder, id); getFileNeighborsRouteHandler(
req,
res,
property,
filter,
search,
getSort(sortProperty, listAllowedSorters),
sortOrder,
id
);
}); });
router.get('/:id', isAuthenticated, async (req, res) => { router.get('/:id', isAuthenticated, async (req, res) => {
@ -117,24 +126,19 @@ router.put('/:id', isAuthenticated, checkPermissions('file', 'edit'), async (req
editFileRouteHandler(req, res); editFileRouteHandler(req, res);
}); });
router.delete( router.delete('/delete', isAuthenticated, checkPermissions('file', 'delete'), async (req, res) => {
'/delete', const filter = await getFilter(
isAuthenticated, req.query.filter ? JSON.parse(req.query.filter) : {},
checkPermissions('file', 'delete'), listAllowedFilters,
async (req, res) => { true
const filter = await getFilter( );
req.query.filter ? JSON.parse(req.query.filter) : {}, const masterFilter = await getFilter(
listAllowedFilters, req.query.masterFilter ? JSON.parse(req.query.masterFilter) : {},
true listAllowedFilters,
); true
const masterFilter = await getFilter( );
req.query.masterFilter ? JSON.parse(req.query.masterFilter) : {}, deleteFileByFilterRouteHandler(req, res, filter, masterFilter);
listAllowedFilters, });
true
);
deleteFileByFilterRouteHandler(req, res, filter, masterFilter);
}
);
router.delete('/:id', isAuthenticated, async (req, res) => { router.delete('/:id', isAuthenticated, async (req, res) => {
deleteFileRouteHandler(req, res); deleteFileRouteHandler(req, res);