mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
Server: little sort refractoring
This commit is contained in:
parent
e4c87ec269
commit
9c2c18f3ab
2 changed files with 17 additions and 12 deletions
|
@ -10,22 +10,21 @@ const validatorsSort = {
|
|||
videosSort
|
||||
}
|
||||
|
||||
function usersSort (req, res, next) {
|
||||
const sortableColumns = constants.SORTABLE_COLUMNS.USERS
|
||||
// Initialize constants here for better performances
|
||||
const SORTABLE_USERS_COLUMNS = createSortableColumns(constants.SORTABLE_COLUMNS.USERS)
|
||||
const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(constants.SORTABLE_COLUMNS.VIDEO_ABUSES)
|
||||
const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(constants.SORTABLE_COLUMNS.VIDEOS)
|
||||
|
||||
checkSort(req, res, next, sortableColumns)
|
||||
function usersSort (req, res, next) {
|
||||
checkSort(req, res, next, SORTABLE_USERS_COLUMNS)
|
||||
}
|
||||
|
||||
function videoAbusesSort (req, res, next) {
|
||||
const sortableColumns = constants.SORTABLE_COLUMNS.VIDEO_ABUSES
|
||||
|
||||
checkSort(req, res, next, sortableColumns)
|
||||
checkSort(req, res, next, SORTABLE_VIDEO_ABUSES_COLUMNS)
|
||||
}
|
||||
|
||||
function videosSort (req, res, next) {
|
||||
const sortableColumns = constants.SORTABLE_COLUMNS.VIDEOS
|
||||
|
||||
checkSort(req, res, next, sortableColumns)
|
||||
checkSort(req, res, next, SORTABLE_VIDEOS_COLUMNS)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
@ -41,3 +40,9 @@ function checkSort (req, res, next, sortableColumns) {
|
|||
|
||||
checkErrors(req, res, next)
|
||||
}
|
||||
|
||||
function createSortableColumns (sortableColumns) {
|
||||
const sortableColumnDesc = sortableColumns.map(sortableColumn => '-' + sortableColumn)
|
||||
|
||||
return sortableColumns.concat(sortableColumnDesc)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue