2021-04-01 00:24:42 +00:00
module . exports = {
friendlyName : 'View pricing' ,
description : 'Display "Pricing" page.' ,
exits : {
success : {
viewTemplatePath : 'pages/pricing'
2022-12-05 20:11:46 +00:00
} ,
badConfig : {
responseType : 'badConfig'
} ,
2021-04-01 00:24:42 +00:00
} ,
fn : async function ( ) {
2022-12-05 20:11:46 +00:00
if ( ! _ . isObject ( sails . config . builtStaticContent ) || ! _ . isArray ( sails . config . builtStaticContent . pricingTable ) ) {
throw { badConfig : 'builtStaticContent.pricingTable' } ;
}
2023-11-23 00:33:32 +00:00
let pricingTableFeatures = sails . config . builtStaticContent . pricingTable ;
let pricingTable = [ ] ;
// Note: These product categories are hardcoded in to reduce complexity, an alternative way of building this from the pricingFeaturesTable is: let productCategories = _.union(_.flatten(_.pluck(pricingTableFeatures, 'productCategories')));
let productCategories = [ 'Endpoint operations' , 'Device management' , 'Vulnerability management' ] ;
for ( let category of productCategories ) {
// Get all the features in that have a productCategories array that contains this category.
let featuresInThisCategory = _ . filter ( pricingTableFeatures , ( feature ) => {
return _ . contains ( feature . productCategories , category ) ;
} ) ;
// Build a dictionary containing the category name, and all features in the category, sorting premium features to the bottom of the list.
let allFeaturesInThisCategory = {
categoryName : category ,
features : _ . sortBy ( featuresInThisCategory , ( feature ) => {
return feature . tier !== 'Free' ;
} )
} ;
// Add the dictionaries to the arrays that we'll use to build the features table.
pricingTable . push ( allFeaturesInThisCategory ) ;
}
2023-06-09 21:52:39 +00:00
2021-04-01 00:24:42 +00:00
// Respond with view.
2023-06-09 21:52:39 +00:00
return {
2023-11-23 00:33:32 +00:00
pricingTable
2023-06-09 21:52:39 +00:00
} ;
2021-04-01 00:24:42 +00:00
}
} ;