pagination.ts 667 B

12345678910111213141516171819202122
  1. import 'express-validator'
  2. import * as express from 'express'
  3. import { PAGINATION } from '../initializers/constants'
  4. function setDefaultPagination (req: express.Request, res: express.Response, next: express.NextFunction) {
  5. if (!req.query.start) req.query.start = 0
  6. else req.query.start = parseInt(req.query.start, 10)
  7. if (!req.query.count) req.query.count = PAGINATION.COUNT.DEFAULT
  8. else req.query.count = parseInt(req.query.count, 10)
  9. if (req.query.count > PAGINATION.COUNT.MAX) req.query.count = PAGINATION.COUNT.MAX
  10. return next()
  11. }
  12. // ---------------------------------------------------------------------------
  13. export {
  14. setDefaultPagination
  15. }