<commit_before>/*global Promise, _*/
exports.validate = function(model) {
  var errors = {};
  //Looping through each attributes.
  for (var attr in getValidatedAttrs(model)) {
    //console.log("Attr", attr);
    if (!model.isValid(attr)) {
      errors[attr] = attr + " not valid."; // Todo: translate the message.
    }
  }
  //Promisify the validations , if there is errors call the reject else call resolve with the model.
  return new Promise(function promiseValidation(resolve, reject) {
    //console.log("Errors", errors);
    if (_.isEmpty(errors)) {
      //console.log('resolve');
      resolve(model);
    } else {
      //console.log('reject');
      reject(errors);
    }
    return undefined;
  });
};

var getValidatedAttrs = function(model) {
  return _.reduce(_.keys(_.result(model, 'validation') || {}), function(memo, key) {
    memo[key] = void 0;
    return memo;
  }, {});
};<commit_msg>Add improve the validation model.<commit_after>/*global Promise, _*/
//Get the domains definition.
var domains = require('./domains');
exports.validate = function(model) {
  var errors = {};
  //Looping through each attributes.
  validateCustomAttributes(model, errors);
  //Promisify the validations , if there is errors call the reject else call resolve with the model.
  return new Promise(function promiseValidation(resolve, reject) {
    //console.log("Errors", errors);
    if (_.isEmpty(errors)) {
      //console.log('resolve');
      resolve(model);
    } else {
      //console.log('reject');
      reject(errors);
    }
    return undefined;
  });
};

var validateCustomAttributes = function validateCustomAttributes(model, errors){
  if(!model){throw new Error('The model should have a metadatas property.');}
  for (var attr in getValidatedAttrs(model)) {
    //console.log("Attr", attr);
    if (!model.isValid(attr)) {
      errors[attr] = attr + " not valid."; // Todo: translate the message.
    }
  }
};


var getValidatedAttrs = function(model) {
  return _.reduce(_.keys(_.result(model, 'validation') || {}), function(memo, key) {
    memo[key] = void 0;
    return memo;
  }, {});
};
//Get the validation attributes from the domain.
var getDomainsAttrs = function getDomainsAttrs(model){
  if(!model){return new Error('The model should have a metadatas property.');}

  //Get the metadatas from the model.
  var metadatas = model.metadatas;
  if(metadatas){

  }
};
{'fraction_non_alphanumeric': 0.14935335836462243, 'fraction_numerical': 0.0008343763037129745, 'mean_word_length': 3.45724907063197, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6941350', 'n_tokens_mistral': 719, 'n_tokens_neox': 712, 'n_words': 201}