Project

General

Profile

1

    
2
import {filter, map, mergeMap} from 'rxjs/operators';
3
import { Injectable } from '@angular/core';
4
import {
5
  Router,
6
  CanActivate,
7
  ActivatedRouteSnapshot,
8
  RouterStateSnapshot,
9
  CanLoad,
10
  Route
11
} from '@angular/router';
12
import {Observable, Subscription} from 'rxjs';
13
import {CommunityService} from '../community/community.service';
14
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
15
import {ConnectHelper} from '../connectHelper';
16
import {properties} from "../../../../environments/environment";
17

    
18
@Injectable()
19
export class ConnectCommunityGuard implements  CanActivate {
20
  sub: Subscription = null;
21

    
22
  constructor(private router: Router,
23
              private communityService: CommunityService) {
24
  }
25

    
26
  check(community: string): Observable<boolean> | boolean {
27
    return this.communityService.isCommunityTypeByState(properties, properties['communityAPI'] + community).pipe(map(isCommunity => {
28
      if(!isCommunity) {
29
        this.router.navigate(['errorcommunity']);
30
      }
31
      return isCommunity;
32
    }));
33
  }
34

    
35
  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
36
    return this.check(route.queryParams['communityId']);
37
  }
38
}
(4-4/8)