From 9fe854e37b649acdce71d6311f99c9b3c7d2f3c7 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Mon, 14 Sep 2026 10:30:10 +0100 Subject: [PATCH] Enhance file management routes by adding 'extension' to allowed sorters and improving code readability 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. --- src/routes/management/files.js | 86 ++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/src/routes/management/files.js b/src/routes/management/files.js index 016eb80..f15d049 100644 --- a/src/routes/management/files.js +++ b/src/routes/management/files.js @@ -15,7 +15,7 @@ const listAllowedFilters = [ 'updatedAt', '_reference', ]; -const listAllowedSorters = ['name', 'type', 'size', 'createdAt', 'temp', 'updatedAt']; +const listAllowedSorters = ['name', 'type', 'size', 'createdAt', 'temp', 'updatedAt', 'extension']; const propertiesAllowedFilters = ['type', 'extension']; import { listFilesRouteHandler, @@ -32,15 +32,24 @@ import { getFileHistoryRouteHandler, searchFilesRouteHandler, getFilePropertyValuesRouteHandler, - - getFileNeighborsRouteHandler + getFileNeighborsRouteHandler, } from '../../services/management/files.js'; // list of files router.get('/', isAuthenticated, checkPermissions('file', 'list'), async (req, res) => { const { page, limit, property, search, sortProperty, sortOrder } = req.query; - const filter = await getFilter(req.query, listAllowedFilters); - listFilesRouteHandler(req, res, page, limit, property, filter, search, getSort(sortProperty, listAllowedSorters), sortOrder); + const filter = await getFilter(req.query, listAllowedFilters); + listFilesRouteHandler( + req, + res, + page, + limit, + property, + filter, + search, + getSort(sortProperty, listAllowedSorters), + sortOrder + ); }); 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); }); -router.get( - '/values', - checkPermissions('file', 'list'), - isAuthenticated, - async (req, res) => { - const { property } = req.query; - 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); +router.get('/values', checkPermissions('file', 'list'), isAuthenticated, async (req, res) => { + const { property } = req.query; + 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); +}); router.get('/search', checkPermissions('file', 'list'), isAuthenticated, async (req, res) => { const { search } = req.query; @@ -98,7 +98,16 @@ router.delete('/:id/flush', isAuthenticated, async (req, res) => { router.get('/neighbors', isAuthenticated, async (req, res) => { const { property, search, sortProperty, sortOrder, id } = req.query; 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) => { @@ -117,24 +126,19 @@ router.put('/:id', isAuthenticated, checkPermissions('file', 'edit'), async (req editFileRouteHandler(req, res); }); -router.delete( - '/delete', - isAuthenticated, - checkPermissions('file', 'delete'), - async (req, res) => { - const filter = await getFilter( - req.query.filter ? JSON.parse(req.query.filter) : {}, - listAllowedFilters, - true - ); - const masterFilter = await getFilter( - req.query.masterFilter ? JSON.parse(req.query.masterFilter) : {}, - listAllowedFilters, - true - ); - deleteFileByFilterRouteHandler(req, res, filter, masterFilter); - } -); +router.delete('/delete', isAuthenticated, checkPermissions('file', 'delete'), async (req, res) => { + const filter = await getFilter( + req.query.filter ? JSON.parse(req.query.filter) : {}, + listAllowedFilters, + true + ); + const masterFilter = await getFilter( + req.query.masterFilter ? JSON.parse(req.query.masterFilter) : {}, + listAllowedFilters, + true + ); + deleteFileByFilterRouteHandler(req, res, filter, masterFilter); +}); router.delete('/:id', isAuthenticated, async (req, res) => { deleteFileRouteHandler(req, res);