Refractor validators

This commit is contained in:
Chocobozzz 2017-11-27 17:30:46 +01:00
parent fcaf1e0aa8
commit a2431b7dcb
No known key found for this signature in database
GPG key ID: 583A612D890159BE
33 changed files with 478 additions and 643 deletions

View file

@ -1,19 +1,8 @@
import { validationResult } from 'express-validator/check'
import * as express from 'express'
import { validationResult } from 'express-validator/check'
import { logger } from '../../helpers'
function checkErrors (req: express.Request, res: express.Response, next: express.NextFunction) {
const errors = validationResult(req)
if (!errors.isEmpty()) {
logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() })
return res.status(400).json({ errors: errors.mapped() })
}
return next()
}
function areValidationErrors (req: express.Request, res: express.Response) {
const errors = validationResult(req)
@ -30,6 +19,5 @@ function areValidationErrors (req: express.Request, res: express.Response) {
// ---------------------------------------------------------------------------
export {
checkErrors,
areValidationErrors
}