Refractor validators
This commit is contained in:
parent
fcaf1e0aa8
commit
a2431b7dcb
33 changed files with 478 additions and 643 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue