fix: Correct validate middleware to use standard express-validator pattern
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:
parent
a0d2fe235e
commit
0fe27033b5
@ -1,23 +1,19 @@
|
||||
// Middleware для валидации запросов с express-validator
|
||||
// Используется после применения валидаций как middleware
|
||||
|
||||
const { validationResult } = require('express-validator');
|
||||
|
||||
const validate = (validations) => {
|
||||
return async (req, res, next) => {
|
||||
// Выполняем все валидации
|
||||
await Promise.all(validations.map(validation => validation.run(req)));
|
||||
const validate = (req, res, next) => {
|
||||
const errors = validationResult(req);
|
||||
if (errors.isEmpty()) {
|
||||
return next();
|
||||
}
|
||||
|
||||
const errors = validationResult(req);
|
||||
if (errors.isEmpty()) {
|
||||
return next();
|
||||
}
|
||||
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
error: 'Validation failed',
|
||||
errors: errors.array(),
|
||||
});
|
||||
};
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
error: 'Validation failed',
|
||||
errors: errors.array(),
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = validate;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user