aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/utils.ts
blob: 55b14010387e6406ac5e88aee4b889b73e3bac01 (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 * as express from 'express'
import { validationResult } from 'express-validator/check'
import { logger } from '../../helpers/logger'

function areValidationErrors (req: express.Request, res: express.Response) {
  const errors = validationResult(req)

  if (!errors.isEmpty()) {
    logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() })
    res.status(400).json({ errors: errors.mapped() })

    return true
  }

  return false
}

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

export {
  areValidationErrors
}