2021-08-27 08:32:44 -04:00
|
|
|
import express from 'express'
|
2020-01-08 18:43:52 -05:00
|
|
|
import { query } from 'express-validator'
|
2020-01-09 03:36:31 -05:00
|
|
|
import { PAGINATION } from '@server/initializers/constants'
|
2021-06-03 11:33:44 -04:00
|
|
|
import { logger } from '../../../helpers/logger'
|
|
|
|
import { areValidationErrors } from '../shared'
|
2020-01-08 18:43:52 -05:00
|
|
|
|
|
|
|
const apPaginationValidator = [
|
2020-01-09 03:36:31 -05:00
|
|
|
query('page')
|
|
|
|
.optional()
|
|
|
|
.isInt({ min: 1 }).withMessage('Should have a valid page number'),
|
|
|
|
query('size')
|
|
|
|
.optional()
|
|
|
|
.isInt({ min: 0, max: PAGINATION.OUTBOX.COUNT.MAX }).withMessage(`Should have a valid page size (max: ${PAGINATION.OUTBOX.COUNT.MAX})`),
|
2020-01-08 18:43:52 -05:00
|
|
|
|
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking pagination parameters', { parameters: req.query })
|
|
|
|
|
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
apPaginationValidator
|
|
|
|
}
|