diff --git a/projects/common/src/fm/services/package-guard.service.ts b/projects/common/src/fm/services/package-guard.service.ts new file mode 100644 index 0000000..8cc41ea --- /dev/null +++ b/projects/common/src/fm/services/package-guard.service.ts @@ -0,0 +1,19 @@ +import {Injectable} from '@angular/core'; +import {ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot} from '@angular/router'; +import {PackageService} from './package.service'; + +@Injectable({ + providedIn: 'root', +}) +export class PackageGuardService implements CanActivate { + + constructor(private packageService: PackageService) { } + + canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { + return route.data && route.data.package && this.hasPackageForRoute(route.data.package); + } + + private hasPackageForRoute(packageId: string): boolean { + return this.packageService.hasPackage(packageId); + } +}