From 39993e75dace43b64db576d887951f3b800c3539 Mon Sep 17 00:00:00 2001 From: Mark van der Wal Date: Fri, 5 Feb 2021 12:51:43 +0100 Subject: [PATCH] added a package guard --- .../src/fm/services/package-guard.service.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 projects/common/src/fm/services/package-guard.service.ts 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); + } +}