const validate = (schema, obj, next) => { const { error } = schema.validate(obj); if (error) { const [{ message }] = error.details; return next({ status: 400, message: `Filed: ${message.replace(/"/g, "")}`, }); } next(); }; module.exports = validate;