import { Injectable } from '@angular/core' ; import { Resolve } from '@angular/router' ; import { Observable , forkJoin } from 'rxjs' ; import { LocalStorage } from '../shared/local-storage.provider' ; import { TVMaze } from '../shared/tv-maze.provider' ; import { Show , Episode , ShowWithEpisodes } from '../../interfaces' ; import { map } from 'rxjs/operators' ; @ Injectable ( ) export class SubscribedShowsEpisodesResolver implements Resolve < ShowWithEpisodes [ ] > { subscribedShows : Show [ ] ; constructor ( private localStorage , private tvMaze ) { this . subscribedShows = localStorage . getItem ( 'subscribedShows' , [ ] ) ; } resolve ( ) { const episodeRequests = this . subscribedShows . map ( ( show ) => { return this . tvMaze . getEpisodes ( show . id ) . pipe ( map ( ( episodes ) : ShowWithEpisodes => { return { episodes , show } ; } ) ) ; } ) ; return forkJoin ( episodeRequests ) ; } }