dist/decorator.js
function validate(method) {
  var decorated = function validateDecorator() {
    var params = method.params;
    var schema = method.schema;

    for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
      args[_key2] = arguments[_key2];
    }

    var value = _combineObject(params, args);
    var normalized = void 0;
    try {
      normalized = _joi2.default.attempt(value, schema);
    } catch (e) {
      if (method.sync) {
        throw e;
      }
      return _promise2.default.reject(e);
    }
    var newArgs = [];
    // Joi will normalize values
    // for example string number '1' to 1
    // if schema type is number
    _lodash2.default.each(params, function (param) {
      newArgs.push(normalized[param]);
    });
    return method.apply(undefined, newArgs);
  };
  return _keepProps(method, decorated);
}
function validate(method) {
  var decorated = function validateDecorator() {
    var params = method.params;
    var schema = method.schema;

    for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
      args[_key2] = arguments[_key2];
    }

    var value = _combineObject(params, args);
    var normalized = void 0;
    try {
      normalized = _joi2.default.attempt(value, schema);
    } catch (e) {
      if (method.sync) {
        throw e;
      }
      return _promise2.default.reject(e);
    }
    var newArgs = [];
    // Joi will normalize values
    // for example string number '1' to 1
    // if schema type is number
    _lodash2.default.each(params, function (param) {
      newArgs.push(normalized[param]);
    });
    return method.apply(undefined, newArgs);
  };
  return _keepProps(method, decorated);
}
function validate ( method ) { var decorated = function validateDecorator ( ) { var params = method . params ; var schema = method . schema ; for ( var _len2 = arguments . length , args = Array ( _len2 ) , _key2 = 0 ; _key2 < _len2 ; _key2 ++ ) { args [ _key2 ] = arguments [ _key2 ] ; } var value = _combineObject ( params , args ) ; var normalized = void 0 ; try { normalized = _joi2 . default . attempt ( value , schema ) ; } catch ( e ) { if ( method . sync ) { throw e ; } return _promise2 . default . reject ( e ) ; } var newArgs = [ ] ; // Joi will normalize values // for example string number '1' to 1 // if schema type is number _lodash2 . default . each ( params , function ( param ) { newArgs . push ( normalized [ param ] ) ; } ) ; return method . apply ( undefined , newArgs ) ; } ; return _keepProps ( method , decorated ) ; }
Decorator for validating with Joi
@param {Function} method the method to decorate
@param {Array} method.params the method parameters
@param {Object} method.schema the joi schema
@param {Boolean} method.sync the flag if method is sync or async
@returns {Function} the decorator
Decorator for validating with Joi