diff options
Diffstat (limited to 'server/middlewares/validators/sort.ts')
-rw-r--r-- | server/middlewares/validators/sort.ts | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts index ebc7333c7..3baee9fb3 100644 --- a/server/middlewares/validators/sort.ts +++ b/server/middlewares/validators/sort.ts | |||
@@ -1,3 +1,6 @@ | |||
1 | import 'express-validator' | ||
2 | import * as express from 'express' | ||
3 | |||
1 | import { checkErrors } from './utils' | 4 | import { checkErrors } from './utils' |
2 | import { logger } from '../../helpers' | 5 | import { logger } from '../../helpers' |
3 | import { SORTABLE_COLUMNS } from '../../initializers' | 6 | import { SORTABLE_COLUMNS } from '../../initializers' |
@@ -7,15 +10,15 @@ const SORTABLE_USERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USERS) | |||
7 | const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES) | 10 | const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES) |
8 | const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) | 11 | const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) |
9 | 12 | ||
10 | function usersSortValidator (req, res, next) { | 13 | function usersSortValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
11 | checkSort(req, res, next, SORTABLE_USERS_COLUMNS) | 14 | checkSort(req, res, next, SORTABLE_USERS_COLUMNS) |
12 | } | 15 | } |
13 | 16 | ||
14 | function videoAbusesSortValidator (req, res, next) { | 17 | function videoAbusesSortValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
15 | checkSort(req, res, next, SORTABLE_VIDEO_ABUSES_COLUMNS) | 18 | checkSort(req, res, next, SORTABLE_VIDEO_ABUSES_COLUMNS) |
16 | } | 19 | } |
17 | 20 | ||
18 | function videosSortValidator (req, res, next) { | 21 | function videosSortValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
19 | checkSort(req, res, next, SORTABLE_VIDEOS_COLUMNS) | 22 | checkSort(req, res, next, SORTABLE_VIDEOS_COLUMNS) |
20 | } | 23 | } |
21 | 24 | ||
@@ -29,7 +32,7 @@ export { | |||
29 | 32 | ||
30 | // --------------------------------------------------------------------------- | 33 | // --------------------------------------------------------------------------- |
31 | 34 | ||
32 | function checkSort (req, res, next, sortableColumns) { | 35 | function checkSort (req: express.Request, res: express.Response, next: express.NextFunction, sortableColumns: string[]) { |
33 | req.checkQuery('sort', 'Should have correct sortable column').optional().isIn(sortableColumns) | 36 | req.checkQuery('sort', 'Should have correct sortable column').optional().isIn(sortableColumns) |
34 | 37 | ||
35 | logger.debug('Checking sort parameters', { parameters: req.query }) | 38 | logger.debug('Checking sort parameters', { parameters: req.query }) |
@@ -37,7 +40,7 @@ function checkSort (req, res, next, sortableColumns) { | |||
37 | checkErrors(req, res, next) | 40 | checkErrors(req, res, next) |
38 | } | 41 | } |
39 | 42 | ||
40 | function createSortableColumns (sortableColumns) { | 43 | function createSortableColumns (sortableColumns: string[]) { |
41 | const sortableColumnDesc = sortableColumns.map(sortableColumn => '-' + sortableColumn) | 44 | const sortableColumnDesc = sortableColumns.map(sortableColumn => '-' + sortableColumn) |
42 | 45 | ||
43 | return sortableColumns.concat(sortableColumnDesc) | 46 | return sortableColumns.concat(sortableColumnDesc) |