Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 28x 28x 49x 49x 28x 43x 43x 43x 43x 43x 43x 6x 43x | import mapObjectKeysToCamel from './to-camel';
import type { ProductCamelCase, ProductSnakeCase } from '../types';
const monthsByTerm: Record< string, number > = { year: 12, 'two years': 24 };
const preparePricing = ( pricing: ProductCamelCase[ 'pricingForUi' ] ) => {
const months = monthsByTerm[ pricing.productTerm ] || 1;
return {
...pricing,
fullPricePerMonth: Math.round( ( pricing.fullPrice / months ) * 100 ) / 100,
discountPricePerMonth: Math.round( ( pricing.discountPrice / months ) * 100 ) / 100,
};
};
export const prepareProductData = ( product: ProductSnakeCase ) => {
// The mapObjectKeysToCamel is typed correctly, however we are adding new fields
// to the product object that don't exist on the global state object
// Therefore we still need to cast the object to the correct type
const camelProduct = mapObjectKeysToCamel( product ) as ProductCamelCase;
camelProduct.features = camelProduct.features || [];
camelProduct.supportedProducts = camelProduct.supportedProducts || [];
Eif ( camelProduct.pricingForUi ) {
camelProduct.pricingForUi = preparePricing( camelProduct.pricingForUi );
camelProduct.pricingForUi.terms = camelProduct.pricingForUi.terms?.map( term =>
preparePricing( term as ProductCamelCase[ 'pricingForUi' ] )
);
}
return camelProduct;
};
|