import { ItineraryService } from '../services/itinerary' ; import { ItineraryDAO } from '../dao/itinerary' ; import { Itinerary } from '../models/itinerary' ; import { Injectable } from '@angular/core' ; class @ Injectable ( ) export class ItineraryManager { public constructor ( private service , private dao ) { } private param { string } line return { Promise < Itinerary > } private downloadItinerary ( line ) { return new Promise < Itinerary > ( resolve => { this . service . getItinerary ( line ) . then ( ( data ) => this . dao . save ( data ) . then ( ( ) => resolve ( data ) ) ) ; } ) ; } param { string } line return { Promise < Itinerary > } public getByLine ( line ) { return new Promise < Itinerary > ( resolve => { this . dao . get ( line ) . then ( it => { if ( it ) resolve ( it ) ; else this . downloadItinerary ( line ) . then ( dit => resolve ( dit ) ) ; } ) ; } ) ; } }