Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { UserDTO } from './../../models/user/user.dto';
- import { UsersService } from './../services/users.service';
- import { Injectable } from '@angular/core';
- import { ActivatedRouteSnapshot, RouterStateSnapshot, Resolve } from '@angular/router';
- import { Observable, EMPTY, zip } from 'rxjs';
- import { catchError, map } from 'rxjs/operators';
- @Injectable()
- export class ProfileResolver implements Resolve<UserDTO> {
- constructor(
- private readonly usersService: UsersService,
- ) { }
- resolve(
- route: ActivatedRouteSnapshot,
- state: RouterStateSnapshot,
- ): Observable<any> {
- const userId = +route.paramMap.get('userId');
- return zip(
- this.usersService.findUserById(userId),
- this.usersService.getUserFollowers(userId),
- this.usersService.getUserFollowing(userId),
- )
- .pipe(
- map(([user, following, followers]) => ({ user, following, followers })),
- catchError(() => {
- return EMPTY;
- })
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement