mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
First typescript iteration
This commit is contained in:
parent
d5f345ed4c
commit
65fcc3119c
113 changed files with 1961 additions and 1784 deletions
|
@ -1,48 +0,0 @@
|
|||
'use strict'
|
||||
|
||||
const checkErrors = require('./utils').checkErrors
|
||||
const constants = require('../../initializers/constants')
|
||||
const logger = require('../../helpers/logger')
|
||||
|
||||
const validatorsSort = {
|
||||
usersSort,
|
||||
videoAbusesSort,
|
||||
videosSort
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
function usersSort (req, res, next) {
|
||||
checkSort(req, res, next, SORTABLE_USERS_COLUMNS)
|
||||
}
|
||||
|
||||
function videoAbusesSort (req, res, next) {
|
||||
checkSort(req, res, next, SORTABLE_VIDEO_ABUSES_COLUMNS)
|
||||
}
|
||||
|
||||
function videosSort (req, res, next) {
|
||||
checkSort(req, res, next, SORTABLE_VIDEOS_COLUMNS)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
module.exports = validatorsSort
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function checkSort (req, res, next, sortableColumns) {
|
||||
req.checkQuery('sort', 'Should have correct sortable column').optional().isIn(sortableColumns)
|
||||
|
||||
logger.debug('Checking sort parameters', { parameters: req.query })
|
||||
|
||||
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