diff --git a/website/api/controllers/view-pricing.js b/website/api/controllers/view-pricing.js index e3c914e0ae..7d07b6b770 100644 --- a/website/api/controllers/view-pricing.js +++ b/website/api/controllers/view-pricing.js @@ -44,36 +44,39 @@ module.exports = { pricingTable.push(allFeaturesInThisCategory); } - let pricingTableForSecurity = _.filter(pricingTable, (category)=>{ - return category.categoryName !== 'Device management' && (category.usualDepartment === 'Security' || category.usualDepartment === undefined); - }); + let pricingTableForSecurity = []; let categoryOrderForSecurityPricingTable = ['Support', 'Deployment', 'Integrations', 'Endpoint operations', 'Vulnerability management']; - // Sort the security-focused pricing table from the order of the elements in the categoryOrderForSecurityPricingTable array. - pricingTableForSecurity.sort((a, b)=>{ - // If there is a category that is not in the list above, sort it to the end of the list. - if(categoryOrderForSecurityPricingTable.indexOf(a.categoryName) === -1){ - return 1; - } else if(categoryOrderForSecurityPricingTable.indexOf(b.categoryName) === -1) { - return -1; - } - return categoryOrderForSecurityPricingTable.indexOf(a.categoryName) - categoryOrderForSecurityPricingTable.indexOf(b.categoryName); - }); + for(let category of categoryOrderForSecurityPricingTable) { + // Get all the features in that have a pricingTableFeatures array that contains this category. + let featuresInThisCategory = _.filter(pricingTableFeatures, (feature)=>{ + return _.contains(feature.pricingTableCategories, category) && (feature.usualDepartment === 'Security' || feature.usualDepartment === undefined); + }); + // Build a dictionary containing the category name, and all features in the category + let allSecurityFeaturesInThisCategory = { + categoryName: category, + features: featuresInThisCategory, + }; + // Add the dictionaries to the arrays that we'll use to build the features table. + pricingTableForSecurity.push(allSecurityFeaturesInThisCategory); + } - let pricingTableForIt = _.filter(pricingTable, (category)=>{ - return category.categoryName !== 'Vulnerability management' && (category.usualDepartment === 'Security' || category.usualDepartment === undefined); - }); let categoryOrderForITPricingTable = [ 'Deployment','Device management', 'Endpoint operations', 'Integrations', 'Support']; + let pricingTableForIt = []; // Sort the IT-focused pricing table from the order of the elements in the categoryOrderForITPricingTable array. - pricingTableForIt.sort((a, b)=>{ - // If there is a category that is not in the list above, sort it to the end of the list. - if(categoryOrderForITPricingTable.indexOf(a.categoryName) === -1){ - return 1; - } else if(categoryOrderForITPricingTable.indexOf(b.categoryName) === -1) { - return -1; - } - return categoryOrderForITPricingTable.indexOf(a.categoryName) - categoryOrderForITPricingTable.indexOf(b.categoryName); - }); + for(let category of categoryOrderForITPricingTable) { + // Get all the features in that have a pricingTableFeatures array that contains this category. + let featuresInThisCategory = _.filter(pricingTableFeatures, (feature)=>{ + return _.contains(feature.pricingTableCategories, category) && (feature.usualDepartment === 'IT' || feature.usualDepartment === undefined); + }); + // Build a dictionary containing the category name, and all features in the category, sorting premium features to the bottom of the list. + let allItFeaturesInThisCategory = { + categoryName: category, + features: featuresInThisCategory, + }; + // Add the dictionaries to the arrays that we'll use to build the features table. + pricingTableForIt.push(allItFeaturesInThisCategory); + } // Respond with view.