// Sortable columns per schema
const SORTABLE_COLUMNS = {
- USERS: [ 'id', '-id', 'username', '-username', 'createdAt', '-createdAt' ],
- VIDEO_ABUSES: [ 'id', '-id', 'createdAt', '-createdAt' ],
- VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdAt', '-createdAt', 'views', '-views' ]
+ USERS: [ 'id', 'username', 'createdAt' ],
+ VIDEO_ABUSES: [ 'id', 'createdAt' ],
+ VIDEOS: [ 'name', 'duration', 'createdAt', 'views' ]
}
const OAUTH_LIFETIME = {
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)
}
// ---------------------------------------------------------------------------
checkErrors(req, res, next)
}
+
+function createSortableColumns (sortableColumns) {
+ const sortableColumnDesc = sortableColumns.map(sortableColumn => '-' + sortableColumn)
+
+ return sortableColumns.concat(sortableColumnDesc)
+}