multy-stub/server/routers/todo/utils.js

20 lines
397 B
JavaScript
Raw Permalink Normal View History

2025-01-18 16:50:58 +03:00
const requiredValidate =
(...fields) =>
(req, res, next) => {
const errors = []
fields.forEach((field) => {
if (!req.body[field]) {
errors.push(field);
}
})
if (errors.length) {
throw new Error(`Не все поля заполнены: ${errors.join(", ")}`);
} else {
next()
}
}
module.exports.requiredValidate = requiredValidate;