require('object.assign').shim();
var isEmpty = require('lodash.isempty');
var flatten = require('lodash.flatten');
var ValidationStrategy = require('./JoiValidationStrategy');

var ValidationFactory = Object.assign({
  isValid: function(errors, key) {
    if (isEmpty(errors)) {
      return true;
    } else {
      return key ? isEmpty(errors[key]) : isEmpty(errors);
    }
  },

  getValidationMessages: function(errors, key) {
    if (isEmpty(errors)) {
      return [];
    } else {
      if (key) {
        return errors[key] || [];
      } else {
        return flatten(Object.keys(errors).map(function(key) { return errors[key] || []; }));
      }
    }
  }
}, ValidationStrategy);

module.exports = ValidationFactory;

require('object.assign').shim();
var isEmpty = require('lodash.isempty');
var flatten = require('lodash.flatten');
var ValidationStrategy = require('./JoiValidationStrategy');

var ValidationFactory = Object.assign({
  getValidationMessages: function(errors, key) {
    errors = errors || {};
    if (isEmpty(errors)) {
      return [];
    } else {
      if (key) {
        return errors[key] || [];
      } else {
        return flatten(Object.keys(errors).map(function(key) { return errors[key] || []; }));
      }
    }
  },

  isValid: function(errors, key) {
    return isEmpty(this.getValidationMessages(errors, key));
  },
}, ValidationStrategy);

module.exports = ValidationFactory;

Simplify `ValidationFactory` even more