2021-08-27 07:32:44 -05:00
|
|
|
import express from 'express'
|
2020-01-08 17:43:52 -06:00
|
|
|
import { query } from 'express-validator'
|
2020-01-09 02:36:31 -06:00
|
|
|
import { PAGINATION } from '@server/initializers/constants'
|
2021-06-03 10:33:44 -05:00
|
|
|
import { areValidationErrors } from '../shared'
|
2020-01-08 17:43:52 -06:00
|
|
|
|
|
|
|
const apPaginationValidator = [
|
2020-01-09 02:36:31 -06:00
|
|
|
query('page')
|
|
|
|
.optional()
|
2022-08-17 07:27:04 -05:00
|
|
|
.isInt({ min: 1 }),
|
2020-01-09 02:36:31 -06:00
|
|
|
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 17:43:52 -06:00
|
|
|
|
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
apPaginationValidator
|
|
|
|
}
|