import {UserDataState} from '../../common/state/UserDataState'; import {QuoteService} from '../../common/services/QuoteService'; import {Quote, Tariff, Bundle} from '../../common/entities/Quote'; import {BoltonName} from '../../common/entities/Enums'; import {LayoutState} from '../../common/state/LayoutState'; import {AnalyticsService} from '../../common/services/AnalyticsService'; export class SuccessEVController implements ng.IController { loading: Boolean; quote: Quote; tariff: Tariff; bundle: Bundle; boltons: QuoteBolton[]; firstName: string; constructor(private $state: ng.ui.IStateService, private $window: ng.IWindowService, private layoutState: LayoutState, private userDataState: UserDataState, private quoteService: QuoteService, private analyticsService: AnalyticsService) { layoutState.title = 'Confirmation'; delete layoutState.back; this.loading = true; this.firstName = this.userDataState.firstName; this.analyticsService.push({event: 'ViewConfirmation'}); } $onInit() { return this.quoteService.getQuote() .then(response => { this.quote = response; this.tariff = this.quote.tariffs[this.userDataState.tariffId]; this.bundle = this.quote.bundles.find(bundle => bundle.name === this.userDataState.bundleName); this.boltons = this.getBoltonsFromQuote(this.quote, this.bundle); this.loading = false; }); } getBoltonsFromQuote(quote: Quote, bundle: Bundle): QuoteBolton[] { return !bundle ? [] : bundle.boltons.map(bundleBolton => { const quoteBolton = quote.boltons.find(quoteBolton => bundleBolton.name === quoteBolton.name); return { name: bundleBolton.name, displayName: quoteBolton.displayName, cost: quoteBolton.cost, description: quoteBolton.description, discountPercentage: bundleBolton.discountPercentage }; }); } } interface QuoteBolton { name: BoltonName, displayName: string, cost: number, description: string, discountPercentage: number } ;