Initial commit

This commit is contained in:
Lorenzo Sanesi
2026-03-26 22:46:03 +01:00
commit 18e0e04700
80 changed files with 13114 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
const { ValidationError } = require('../shared/errors');
const validate = (schema) => {
return (req, res, next) => {
const { error, value } = schema.validate(req.body, {
abortEarly: false,
stripUnknown: true,
});
if (error) {
const errors = error.details.map((detail) => ({
field: detail.path.join('.'),
message: detail.message,
}));
return next(new ValidationError('Validation failed', errors));
}
req.body = value;
next();
};
};
module.exports = { validate };