39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
|
|
import {filter, map, mergeMap} from 'rxjs/operators';
|
|
import { Injectable } from '@angular/core';
|
|
import {
|
|
Router,
|
|
CanActivate,
|
|
ActivatedRouteSnapshot,
|
|
RouterStateSnapshot,
|
|
CanLoad,
|
|
Route
|
|
} from '@angular/router';
|
|
import {Observable, Subscription} from 'rxjs';
|
|
import {CommunityService} from '../community/community.service';
|
|
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
|
|
import {ConnectHelper} from '../connectHelper';
|
|
import {properties} from "../../../../environments/environment";
|
|
|
|
@Injectable()
|
|
export class ConnectCommunityGuard implements CanActivate {
|
|
sub: Subscription = null;
|
|
|
|
constructor(private router: Router,
|
|
private communityService: CommunityService) {
|
|
}
|
|
|
|
check(community: string): Observable<boolean> | boolean {
|
|
return this.communityService.isCommunityTypeByState(properties, properties['communityAPI'] + community).pipe(map(isCommunity => {
|
|
if(!isCommunity) {
|
|
this.router.navigate(['errorcommunity']);
|
|
}
|
|
return isCommunity;
|
|
}));
|
|
}
|
|
|
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
|
return this.check(route.queryParams['communityId']);
|
|
}
|
|
}
|