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
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:
parent
52162e1ec6
commit
9fe854e37b
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user