Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module.exports = {
intersection: function(array1, array2) {
var returnedArray = [];
for (var i = 0; i < array1.length; i++) {
if(array2.includes(array1[i])){
returnedArray.push(array1[i]);
}
}
return returnedArray;
},
isSubset: function(containingArray, isSubsetArray){
if(containingArray.length < isSubsetArray.length){
return false;
}
for (var i = 0; i < isSubsetArray.length; i++) {
if(!containingArray.includes(isSubsetArray[i])){
return false;
}
}
return true;
},
paramsRequire: function(dictionary, array2){
array1 = Object.keys(dictionary);
var returnedArray = [];
for (var i = 0; i < array1.length; i++) {
if(array2.includes(array1[i])){
returnedArray.push(array1[i]);
}
}
var params = {};
for(var x = 0; x < returnedArray.length; x++){
params[returnedArray[x]] = dictionary[returnedArray[x]];
}
return params;
},
makeId: function(length){
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < length; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
}
var companyParamsRequirements = [
"name",
"billing_address",
"billing_zip",
"billing_city",
"billing_street",
"billing_state",
"billing_suite",
"contactFirstName",
"contactLastName",
"fourDigitPin",
"numberOfEmployees",
"contactEmail",
"showBilling",
"email",
"company_name",
"contactId",
"phoneNumber",
"address",
"suite",
"state",
"city",
"zip",
"logoURL",
"rate1",
"rate2",
"callingPin",
"authNetId",
"held"
]
var allowedParameters = Scripts.paramsRequire(req.body, companyParamsRequirements);
var company = models.Company.create(allowedParameters).then(function(company){
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment