aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/sort.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/sort.ts')
-rw-r--r--server/middlewares/validators/sort.ts28
1 files changed, 12 insertions, 16 deletions
diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts
index 3baee9fb3..71b18acb0 100644
--- a/server/middlewares/validators/sort.ts
+++ b/server/middlewares/validators/sort.ts
@@ -1,4 +1,4 @@
1import 'express-validator' 1import { query } from 'express-validator/check'
2import * as express from 'express' 2import * as express from 'express'
3 3
4import { checkErrors } from './utils' 4import { checkErrors } from './utils'
@@ -10,17 +10,9 @@ const SORTABLE_USERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USERS)
10const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES) 10const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES)
11const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) 11const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS)
12 12
13function usersSortValidator (req: express.Request, res: express.Response, next: express.NextFunction) { 13const usersSortValidator = checkSort(SORTABLE_USERS_COLUMNS)
14 checkSort(req, res, next, SORTABLE_USERS_COLUMNS) 14const videoAbusesSortValidator = checkSort(SORTABLE_VIDEO_ABUSES_COLUMNS)
15} 15const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS)
16
17function videoAbusesSortValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
18 checkSort(req, res, next, SORTABLE_VIDEO_ABUSES_COLUMNS)
19}
20
21function videosSortValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
22 checkSort(req, res, next, SORTABLE_VIDEOS_COLUMNS)
23}
24 16
25// --------------------------------------------------------------------------- 17// ---------------------------------------------------------------------------
26 18
@@ -32,12 +24,16 @@ export {
32 24
33// --------------------------------------------------------------------------- 25// ---------------------------------------------------------------------------
34 26
35function checkSort (req: express.Request, res: express.Response, next: express.NextFunction, sortableColumns: string[]) { 27function checkSort (sortableColumns: string[]) {
36 req.checkQuery('sort', 'Should have correct sortable column').optional().isIn(sortableColumns) 28 return [
29 query('sort').optional().isIn(sortableColumns).withMessage('Should have correct sortable column'),
37 30
38 logger.debug('Checking sort parameters', { parameters: req.query }) 31 (req: express.Request, res: express.Response, next: express.NextFunction) => {
32 logger.debug('Checking sort parameters', { parameters: req.query })
39 33
40 checkErrors(req, res, next) 34 checkErrors(req, res, next)
35 }
36 ]
41} 37}
42 38
43function createSortableColumns (sortableColumns: string[]) { 39function createSortableColumns (sortableColumns: string[]) {