Advertisement
nikolayneykov

Untitled

Dec 3rd, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { UserDTO } from './../../models/user/user.dto';
  2. import { UsersService } from './../services/users.service';
  3. import { Injectable } from '@angular/core';
  4. import { ActivatedRouteSnapshot, RouterStateSnapshot, Resolve } from '@angular/router';
  5. import { Observable, EMPTY, zip } from 'rxjs';
  6. import { catchError, map } from 'rxjs/operators';
  7.  
  8. @Injectable()
  9. export class ProfileResolver implements Resolve<UserDTO> {
  10.   constructor(
  11.     private readonly usersService: UsersService,
  12.   ) { }
  13.  
  14.   resolve(
  15.     route: ActivatedRouteSnapshot,
  16.     state: RouterStateSnapshot,
  17.   ): Observable<any> {
  18.     const userId = +route.paramMap.get('userId');
  19.  
  20.     return zip(
  21.       this.usersService.findUserById(userId),
  22.       this.usersService.getUserFollowers(userId),
  23.       this.usersService.getUserFollowing(userId),
  24.     )
  25.       .pipe(
  26.         map(([user, following, followers]) => ({ user, following, followers })),
  27.         catchError(() => {
  28.           return EMPTY;
  29.         })
  30.       );
  31.   }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement