function validateCatalog(id, type) {
  array[id].validation = [];
  var categories = [...new Set(array[id].data.map(x => x.category))];
  var settings = validationSettings["interaction studio"][type];
  // check schema matches
  if(JSON.stringify(sort(array[id].meta.fields)) == JSON.stringify(sort(settings.schema))){
    array[id].validation.push(settings.messages.schema[1]);
  } else {
    array[id].validation.push(settings.messages.schema[0]); 
  }
  // check fields count
  if(array[id].meta.fields.length > settings.schema.length){
    array[id].validation.push(settings.messages.fieldCount[0]);
  }
  // check min row count
  if(array[id].data.length >= settings.minRows){
    array[id].validation.push(settings.messages.rowCount[1]);
  } else {
    array[id].validation.push(settings.messages.rowCount[0]); 
  }
  // check for duplicates
  var idOptions = sort([...new Set(array[id].data.map(x => x._id))]);
  array.ids = array.ids.concat(idOptions);
  if(array[id].data.length == idOptions.length){
    array[id].validation.push(settings.messages.duplicates[1]);
  } else {
    array[id].validation.push(settings.messages.duplicates[0]); 
  }
  // check min category count
  if(categories.length >= settings.minCategories){
    array[id].validation.push(settings.messages.categoryCount[1]);
  } else {
    array[id].validation.push(settings.messages.categoryCount[0]); 
  }
  // check price format
  if(type == 'product'){
    var priceOptions = sort([...new Set(array[id].data.map(x => x.price))]);
    var priceOptions = priceOptions.filter(function(v){return v!==''});
    if((!isNaN(parseFloat(priceOptions[0])) && !isNaN(parseFloat(priceOptions[priceOptions.length-1])) && array[id].meta.fields.indexOf('price')>-1) || priceOptions.length ==0){
      array[id].validation.push(settings.messages.price[1]);
    } else {
      array[id].validation.push(settings.messages.price[0])
    }
    // Check listPrice
    var priceOptions = sort([...new Set(array[id].data.map(x => x.listPrice))]);
    var priceOptions = priceOptions.filter(function(v){return v!==''});
    if((!isNaN(parseFloat(priceOptions[0])) && !isNaN(parseFloat(priceOptions[priceOptions.length-1])) && array[id].meta.fields.indexOf('price')>-1) || priceOptions.length ==0){
      array[id].validation.push(settings.messages.listPrice[1]);
    } else {
      array[id].validation.push(settings.messages.listPrice[0])
    }
  }
}
// Function to validate each catalog type based on default settings
Function to validate each catalog type based on default settings
Function to validate each catalog type based on default settings
function validateCatalog(id, type) {
  array[id].validation = [];
  var categories = [...new Set(array[id].data.map(x => x.category))];
  var settings = validationSettings["interaction studio"][type];
  if(JSON.stringify(sort(array[id].meta.fields)) == JSON.stringify(sort(settings.schema))){
    array[id].validation.push(settings.messages.schema[1]);
  } else {
    array[id].validation.push(settings.messages.schema[0]); 
  }
  if(array[id].meta.fields.length > settings.schema.length){
    array[id].validation.push(settings.messages.fieldCount[0]);
  }
  if(array[id].data.length >= settings.minRows){
    array[id].validation.push(settings.messages.rowCount[1]);
  } else {
    array[id].validation.push(settings.messages.rowCount[0]); 
  }
  var idOptions = sort([...new Set(array[id].data.map(x => x._id))]);
  array.ids = array.ids.concat(idOptions);
  if(array[id].data.length == idOptions.length){
    array[id].validation.push(settings.messages.duplicates[1]);
  } else {
    array[id].validation.push(settings.messages.duplicates[0]); 
  }
  if(categories.length >= settings.minCategories){
    array[id].validation.push(settings.messages.categoryCount[1]);
  } else {
    array[id].validation.push(settings.messages.categoryCount[0]); 
  }
  if(type == 'product'){
    var priceOptions = sort([...new Set(array[id].data.map(x => x.price))]);
    var priceOptions = priceOptions.filter(function(v){return v!==''});
    if((!isNaN(parseFloat(priceOptions[0])) && !isNaN(parseFloat(priceOptions[priceOptions.length-1])) && array[id].meta.fields.indexOf('price')>-1) || priceOptions.length ==0){
      array[id].validation.push(settings.messages.price[1]);
    } else {
      array[id].validation.push(settings.messages.price[0])
    }
    var priceOptions = sort([...new Set(array[id].data.map(x => x.listPrice))]);
    var priceOptions = priceOptions.filter(function(v){return v!==''});
    if((!isNaN(parseFloat(priceOptions[0])) && !isNaN(parseFloat(priceOptions[priceOptions.length-1])) && array[id].meta.fields.indexOf('price')>-1) || priceOptions.length ==0){
      array[id].validation.push(settings.messages.listPrice[1]);
    } else {
      array[id].validation.push(settings.messages.listPrice[0])
    }
  }
}
function validateCatalog ( id , type ) { array [ id ] . validation = [ ] ; var categories = [ ... new Set ( array [ id ] . data . map ( x => x . category ) ) ] ; var settings = validationSettings [ "interaction studio" ] [ type ] ; if ( JSON . stringify ( sort ( array [ id ] . meta . fields ) ) == JSON . stringify ( sort ( settings . schema ) ) ) { array [ id ] . validation . push ( settings . messages . schema [ 1 ] ) ; } else { array [ id ] . validation . push ( settings . messages . schema [ 0 ] ) ; } if ( array [ id ] . meta . fields . length > settings . schema . length ) { array [ id ] . validation . push ( settings . messages . fieldCount [ 0 ] ) ; } if ( array [ id ] . data . length >= settings . minRows ) { array [ id ] . validation . push ( settings . messages . rowCount [ 1 ] ) ; } else { array [ id ] . validation . push ( settings . messages . rowCount [ 0 ] ) ; } var idOptions = sort ( [ ... new Set ( array [ id ] . data . map ( x => x . _id ) ) ] ) ; array . ids = array . ids . concat ( idOptions ) ; if ( array [ id ] . data . length == idOptions . length ) { array [ id ] . validation . push ( settings . messages . duplicates [ 1 ] ) ; } else { array [ id ] . validation . push ( settings . messages . duplicates [ 0 ] ) ; } if ( categories . length >= settings . minCategories ) { array [ id ] . validation . push ( settings . messages . categoryCount [ 1 ] ) ; } else { array [ id ] . validation . push ( settings . messages . categoryCount [ 0 ] ) ; } if ( type == 'product' ) { var priceOptions = sort ( [ ... new Set ( array [ id ] . data . map ( x => x . price ) ) ] ) ; var priceOptions = priceOptions . filter ( function ( v ) { return v !== '' } ) ; if ( ( ! isNaN ( parseFloat ( priceOptions [ 0 ] ) ) && ! isNaN ( parseFloat ( priceOptions [ priceOptions . length - 1 ] ) ) && array [ id ] . meta . fields . indexOf ( 'price' ) > - 1 ) || priceOptions . length == 0 ) { array [ id ] . validation . push ( settings . messages . price [ 1 ] ) ; } else { array [ id ] . validation . push ( settings . messages . price [ 0 ] ) } var priceOptions = sort ( [ ... new Set ( array [ id ] . data . map ( x => x . listPrice ) ) ] ) ; var priceOptions = priceOptions . filter ( function ( v ) { return v !== '' } ) ; if ( ( ! isNaN ( parseFloat ( priceOptions [ 0 ] ) ) && ! isNaN ( parseFloat ( priceOptions [ priceOptions . length - 1 ] ) ) && array [ id ] . meta . fields . indexOf ( 'price' ) > - 1 ) || priceOptions . length == 0 ) { array [ id ] . validation . push ( settings . messages . listPrice [ 1 ] ) ; } else { array [ id ] . validation . push ( settings . messages . listPrice [ 0 ] ) } } }
Function to validate each catalog type based on default settings
Function to validate each catalog type based on default settings
// check schema matches // check fields count // check min row count // check for duplicates // check min category count // check price format // Check listPrice