All files / src/app/core/models/price-item price-item.helper.ts

71.42% Statements 5/7
100% Branches 6/6
50% Functions 2/4
71.42% Lines 5/7

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 34 35 36 37 38 39 40 41 42 43 44          129x   77x 75x                 2x 2x                                                  
import { Price, Pricing, ScaledPrice } from 'ish-core/models/price/price.model';
import { ProductPriceDetails } from 'ish-core/models/product-prices/product-prices.model';
 
import { PriceItem, ScaledPriceItem } from './price-item.model';
 
export class PriceItemHelper {
  static selectType(priceItem: PriceItem, type: 'gross' | 'net'): Price {
    if (priceItem && type) {
      return {
        type: 'Money',
        currency: priceItem.currency,
        value: priceItem[type],
      };
    }
  }
 
  static selectScaledPriceType(priceItem: ScaledPriceItem, type: 'gross' | 'net'): ScaledPrice {
    if (priceItem && type) {
      return {
        type: 'Money',
        currency: priceItem.currency,
        value: priceItem[type],
        minQuantity: priceItem.minQuantity,
      };
    }
  }
 
  static selectPricing(priceDetails: ProductPriceDetails, type: 'gross' | 'net'): Pricing {
    return {
      salePrice: PriceItemHelper.selectType(priceDetails?.prices?.salePrice, type),
      listPrice: PriceItemHelper.selectType(priceDetails?.prices?.listPrice, type),
      scaledPrices: priceDetails?.prices?.scaledPrices?.map(priceItem =>
        PriceItemHelper.selectScaledPriceType(priceItem, type)
      ),
      minSalePrice: PriceItemHelper.selectType(priceDetails?.prices?.minSalePrice, type),
      minListPrice: PriceItemHelper.selectType(priceDetails?.prices?.minListPrice, type),
      maxSalePrice: PriceItemHelper.selectType(priceDetails?.prices?.maxSalePrice, type),
      maxListPrice: PriceItemHelper.selectType(priceDetails?.prices?.maxListPrice, type),
      summedUpSalePrice: PriceItemHelper.selectType(priceDetails?.prices?.summedUpSalePrice, type),
      summedUpListPrice: PriceItemHelper.selectType(priceDetails?.prices?.summedUpListPrice, type),
    };
  }
}