pagination.ts 639 B

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