mirror of
https://github.com/20kaushik02/express-sequelize-backend-template.git
synced 2026-01-25 07:14:06 +00:00
packages fix, validator update
This commit is contained in:
@@ -15,10 +15,21 @@ const validate = (req, res, next) => {
|
||||
if (errors.isEmpty()) {
|
||||
return next();
|
||||
}
|
||||
|
||||
const extractedErrors = []
|
||||
errors.array().map(err => extractedErrors.push({
|
||||
[err.param]: err.msg
|
||||
}));
|
||||
errors.array().forEach(err => {
|
||||
if (err.type === 'alternative') {
|
||||
err.nestedErrors.forEach(nestedErr => {
|
||||
extractedErrors.push({
|
||||
[nestedErr.path]: nestedErr.msg
|
||||
});
|
||||
});
|
||||
} else if (err.type === 'field') {
|
||||
extractedErrors.push({
|
||||
[err.path]: err.msg
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return res.status(400).send({
|
||||
message: getNestedValuesString(extractedErrors),
|
||||
|
||||
Reference in New Issue
Block a user