Projekt

Obecné

Profil

Stáhnout (1.01 KB) Statistiky
| Větev: | Tag: | Revize:
1 4bd9d9f6 Hung Hoang
import {Injectable} from '@angular/core';
2
import {UserService} from '../api/user.service';
3
import {UserProfile} from '../../models/user.model';
4
import {MenuItem} from '../../models/menu-item.model';
5
import {UserType} from '../../enums/common.enum';
6
import {Observable, of} from 'rxjs';
7
8
const MENU_ITEMS: MenuItem[] = [
9
  {name: 'Zaměstnanci', routePath: 'employees'},
10
  {name: 'Dashboard', routePath: 'dashboard'},
11
];
12
13
@Injectable({
14
  providedIn: 'root'
15
})
16
export class MenuService {
17
18
  constructor(private userService: UserService) { }
19
20
  getMenuItems() {
21
    const menuItems: MenuItem[] = [];
22
    menuItems.push({name: 'Dashboard', routePath: 'dashboard'});
23
24
    return new Observable((observer) => {
25
      this.userService.getLoggedUserProfile()
26
        .subscribe((profile: UserProfile) => {
27
          if (profile.role === UserType.EMPLOYER) {
28
            menuItems.push({name: 'Zaměstnanci', routePath: 'employees'});
29
          }
30
31
          observer.next(menuItems);
32
          observer.complete();
33
        });
34
    });
35
  }
36
}