school.capacity.locked.guard.ts 687 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
import { Injectable } from '@angular/core';
import { CanActivate } from '@angular/router';
import { AuthService } from '../services/auth.service';
import { SCHOOL_ROLE } from '../constants';
import { Router } from '@angular/router';

@Injectable()
export default class SchoolCapacityLockedGuard implements CanActivate {

  constructor(private authService: AuthService, private router: Router) {}

  canActivate() {
    return this.authService.isCapacityLocked(SCHOOL_ROLE).then(isLocked => {
        if (isLocked) {
            this.router.navigate(['/school']);
            return false;
        } else
            return true;
    }).catch(err => {
        return false;
    });
  }
}