multy-stub/server/routers/todo/utils.js
Primakov Alexandr Alexandrovich fb644b6f7b create todo list
2025-01-18 16:50:58 +03:00

20 lines
397 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;