Merge dev: Fix validate middleware
Some checks are pending
CI/CD / lint-and-build (push) Waiting to run
Some checks are pending
CI/CD / lint-and-build (push) Waiting to run
This commit is contained in:
commit
df50662d18
@ -1,12 +1,9 @@
|
|||||||
// Middleware для валидации запросов с express-validator
|
// Middleware для валидации запросов с express-validator
|
||||||
|
// Используется после применения валидаций как middleware
|
||||||
|
|
||||||
const { validationResult } = require('express-validator');
|
const { validationResult } = require('express-validator');
|
||||||
|
|
||||||
const validate = (validations) => {
|
const validate = (req, res, next) => {
|
||||||
return async (req, res, next) => {
|
|
||||||
// Выполняем все валидации
|
|
||||||
await Promise.all(validations.map(validation => validation.run(req)));
|
|
||||||
|
|
||||||
const errors = validationResult(req);
|
const errors = validationResult(req);
|
||||||
if (errors.isEmpty()) {
|
if (errors.isEmpty()) {
|
||||||
return next();
|
return next();
|
||||||
@ -17,7 +14,6 @@ const validate = (validations) => {
|
|||||||
error: 'Validation failed',
|
error: 'Validation failed',
|
||||||
errors: errors.array(),
|
errors: errors.array(),
|
||||||
});
|
});
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = validate;
|
module.exports = validate;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user