import { Injectable } from '@angular/core' ; import { ActivatedRouteSnapshot , Resolve , Router } from '@angular/router' ; import { of , Observable } from 'rxjs' ; import { catchError , switchMap , take } from 'rxjs/operators' ; import { AuthenticationService , ProjectService } from '@core/services/index.service' ; import { IProject , ProjectModel } from '@shared/models/index.model' ; @ Injectable ( { providedIn : 'root' , } ) export class EditProjectResolver implements Resolve < IProject > { param authService param projectService param router constructor ( private authService , private projectService , private router ) { } param route resolve ( route ) { return this . projectService . findOneById ( route . params . projectUid ) . pipe ( take ( 1 ) , switchMap ( ( project ) => { if ( ! project || ( project . isPrivate ( ) && ! project . isAdmin ( this . authService . profile . uid ) ) ) { this . router . navigate ( [ '/projects' ] ) ; return of ( new ProjectModel ( { uid : 'error' } ) ) ; } return of ( project ) ; } ) , catchError ( ( ) => { this . router . navigate ( [ '/projects' ] ) ; return of ( new ProjectModel ( { uid : 'error' } ) ) ; } ) ) ; } }