You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

18 regels
617 B

  1. const validator = require('../validator');
  2. module.exports = {
  3. validate: function(options) {
  4. const data = this.parse(options.data);
  5. const noError = this.parseOptional(options.noError, 'boolean', false);
  6. return validator.validateData(this, data, noError);
  7. },
  8. error: function(options, name) {
  9. const message = this.parseRequired(options.message, 'string', 'validator.error: message is required.');
  10. const error = { [options.fieldName ? 'form' : 'data']: {[options.fieldName || name]: message }};
  11. this.res.status(400).json(error);
  12. },
  13. };