import { Injectable } from '@angular/core' ; import { ActivatedRouteSnapshot , Resolve , Router } from '@angular/router' ; import { AngularFireFunctions } from '@angular/fire/functions' ; import { of , Observable } from 'rxjs' ; import { catchError , take , tap } from 'rxjs/operators' ; import { ProjectService } from '@core/services/index.service' ; import { IProject , ProjectModel } from '@shared/models/index.model' ; @ Injectable ( { providedIn : 'root' , } ) export class ViewProjectResolver implements Resolve < IProject > { param fns param projectService param router constructor ( private fns , private projectService , private router ) { } param route resolve ( route ) { const callable = this . fns . httpsCallable ( 'updateProjectViews' ) ; return this . projectService . findOneById ( route . params . projectUid ) . pipe ( take ( 1 ) , tap ( ( ) => callable ( { projectUid : route . params . projectUid } ) ) , catchError ( ( ) => { this . router . navigate ( [ '/' ] ) ; return of ( new ProjectModel ( { uid : 'error' } ) ) ; } ) ) ; } }