diff options
Diffstat (limited to 'server/middlewares/validators/sort.ts')
-rw-r--r-- | server/middlewares/validators/sort.ts | 28 |
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 @@ | |||
1 | import 'express-validator' | 1 | import { query } from 'express-validator/check' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | 3 | ||
4 | import { checkErrors } from './utils' | 4 | import { checkErrors } from './utils' |
@@ -10,17 +10,9 @@ const SORTABLE_USERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USERS) | |||
10 | const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES) | 10 | const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES) |
11 | const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) | 11 | const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) |
12 | 12 | ||
13 | function usersSortValidator (req: express.Request, res: express.Response, next: express.NextFunction) { | 13 | const usersSortValidator = checkSort(SORTABLE_USERS_COLUMNS) |
14 | checkSort(req, res, next, SORTABLE_USERS_COLUMNS) | 14 | const videoAbusesSortValidator = checkSort(SORTABLE_VIDEO_ABUSES_COLUMNS) |
15 | } | 15 | const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS) |
16 | |||
17 | function videoAbusesSortValidator (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
18 | checkSort(req, res, next, SORTABLE_VIDEO_ABUSES_COLUMNS) | ||
19 | } | ||
20 | |||
21 | function 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 | ||
35 | function checkSort (req: express.Request, res: express.Response, next: express.NextFunction, sortableColumns: string[]) { | 27 | function 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 | ||
43 | function createSortableColumns (sortableColumns: string[]) { | 39 | function createSortableColumns (sortableColumns: string[]) { |