import { Injectable } from '@angular/core' ; import { ActivatedRouteSnapshot , Resolve , RouterStateSnapshot } from '@angular/router' ; import { UserSetting } from '../models/user-setting' ; import { Observable } from 'rxjs' ; import { UserSettingsDBService } from '../services/user-settings-db.service' ; import { catchError , map } from 'rxjs/operators' ; import { HttpResponse } from '@angular/common/http' ; import { APIGetMultiResponse } from '../../../services/models/api-response' ; /**
 * Resolver for the current user settings of a URL.
 */ @ Injectable ( { providedIn : 'root' } ) export class UserSettingsResolver implements Resolve < UserSetting | unknown > { constructor ( private userSettingsDB ) { } param route param state public resolve ( route , state ) { const ident = state . url . toString ( ) . substring ( 1 ) . split ( '/' ) . join ( '-' ) ; return this . userSettingsDB . getSetting ( ident ) . pipe ( map ( ( setting ) => { return setting ; } ) , catchError ( ( error ) => { console . error ( `No user setting for the route: ${ ident } | Error: ${ error }` ) ; return undefined ; } ) ) ; } }