aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/pagination.ts
blob: 83304940f38af1bc386e045717375b1dab47af3d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import 'express-validator'
import * as express from 'express'

import { PAGINATION } from '../initializers/constants'

function setDefaultPagination (req: express.Request, res: express.Response, next: express.NextFunction) {
  if (!req.query.start) req.query.start = 0
  else req.query.start = parseInt(req.query.start, 10)

  if (!req.query.count) req.query.count = PAGINATION.COUNT.DEFAULT
  else req.query.count = parseInt(req.query.count, 10)

  if (req.query.count > PAGINATION.COUNT.MAX) req.query.count = PAGINATION.COUNT.MAX

  return next()
}

// ---------------------------------------------------------------------------

export {
  setDefaultPagination
}