2020-11-11 15:43:13 +01:00
|
|
|
import {take, tap} from 'rxjs/operators';
|
|
|
|
import {Injectable} from '@angular/core';
|
2019-03-07 16:43:54 +01:00
|
|
|
import {
|
|
|
|
Router,
|
|
|
|
CanActivate,
|
|
|
|
ActivatedRouteSnapshot,
|
|
|
|
RouterStateSnapshot,
|
2020-11-11 15:43:13 +01:00
|
|
|
|
2019-03-07 16:43:54 +01:00
|
|
|
} from '@angular/router';
|
2020-07-17 01:08:10 +02:00
|
|
|
import {Observable, Subscription} from 'rxjs';
|
2019-03-07 16:43:54 +01:00
|
|
|
import {CommunityService} from '../community/community.service';
|
2020-07-17 01:08:10 +02:00
|
|
|
import {properties} from "../../../../environments/environment";
|
2019-03-07 16:43:54 +01:00
|
|
|
|
|
|
|
@Injectable()
|
2020-11-11 15:43:13 +01:00
|
|
|
export class ConnectCommunityGuard implements CanActivate {
|
2020-07-17 01:08:10 +02:00
|
|
|
sub: Subscription = null;
|
2019-03-07 16:43:54 +01:00
|
|
|
|
|
|
|
constructor(private router: Router,
|
2020-08-14 11:49:35 +02:00
|
|
|
private communityService: CommunityService) {
|
2019-03-07 16:43:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
check(community: string): Observable<boolean> | boolean {
|
2021-02-19 18:50:34 +01:00
|
|
|
return this.communityService.isCommunityType(community).pipe(take(1), tap(isCommunity => {
|
2020-11-11 15:43:13 +01:00
|
|
|
if (!isCommunity) {
|
2020-08-14 11:49:35 +02:00
|
|
|
this.router.navigate(['errorcommunity']);
|
|
|
|
}
|
|
|
|
}));
|
2019-03-07 16:43:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
|
|
|
return this.check(route.queryParams['communityId']);
|
|
|
|
}
|
|
|
|
}
|