validate.js 284 B

12345678910111213
  1. const validate = (schema, obj, next) => {
  2. const { error } = schema.validate(obj);
  3. if (error) {
  4. const [{ message }] = error.details;
  5. return next({
  6. status: 400,
  7. message: `Filed: ${message.replace(/"/g, "")}`,
  8. });
  9. }
  10. next();
  11. };
  12. module.exports = validate;