Projekt

Obecné

Profil

Stáhnout (5.4 KB) Statistiky
| Větev: | Tag: | Revize:
1
import {Injectable} from '@angular/core';
2
import {HttpClient, HttpParams} from '@angular/common/http';
3
import {BasicService} from './basic.service';
4
import {catchError} from 'rxjs/operators';
5

    
6
import {AuthorizationRequest, VacationRequest} from '../../models/requests.model';
7
import {Languages, ProfileStatus} from '../../enums/common.enum';
8
import {Observable} from 'rxjs';
9
import {UserBasicInformation} from '../../models/user.model';
10
import {MatSnackBar} from '@angular/material';
11
import {TranslateService} from '@ngx-translate/core';
12

    
13
@Injectable({
14
  providedIn: 'root'
15
})
16
export class UsersService extends BasicService {
17
  private _usersUrl = this.baseUrl + '/api/users';
18

    
19
  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) {
20
    super(http, snackBar, translateService);
21
  }
22

    
23
  /**
24
   * Returns all authorized users
25
   */
26
  getAuthorizedUsers() {
27
    return this.makeGetUsersApiCall(null, ProfileStatus.AUTHORIZED);
28
  }
29

    
30
  /**
31
   * Returns all authorized users with specified language
32
   * overloaded version of getAuthorizedUsers
33
   * @param language filter users based on language
34
   */
35
  getAuthorizedUsersWithLanguage(language: Languages) {
36
    return this.makeGetUsersApiCall(language, ProfileStatus.AUTHORIZED);
37
  }
38

    
39
  /**
40
   * Returns all pending users
41
   */
42
  getPendingUsers() {
43
    return this.makeGetUsersApiCall(null, ProfileStatus.PENDING);
44
  }
45

    
46
  /**
47
   * Returns all pending users with specified language
48
   * overloaded version of getPendingUsers
49
   * @param language filter users based on language
50
   */
51
  getPendingUsersWithLanguage(language: Languages) {
52
    return this.makeGetUsersApiCall(language, ProfileStatus.PENDING);
53
  }
54

    
55
  /**
56
   * Return all rejected users
57
   */
58
  getRejectedUsers() {
59
    return this.makeGetUsersApiCall(null, ProfileStatus.REJECTED);
60
  }
61

    
62
  /**
63
   * Returns all rejected users with specified language
64
   * overloaded version of getRejectedUsers
65
   * @param language filter users based on language
66
   */
67
  getRejectedUsersWithLanguage(language: Languages) {
68
    return this.makeGetUsersApiCall(language, ProfileStatus.REJECTED);
69
  }
70

    
71
 /**
72
  * Default api call which returns all users in the database
73
  * regardless of language and status
74
  */
75
  getUsers() {
76
    return this.makeGetUsersApiCall();
77
  }
78

    
79
  /**
80
   * Returns all vacation requests specified by status, if status
81
   * is not specified, returns all vacation requests
82
   * @param status optional vacation request status
83
   */
84
  getVacationRequests(status?: string) {
85
    return this.makeGetVacationRequestsApiCall( null, status);
86
  }
87

    
88
  /**
89
   * Returns vacations filtered by language
90
   * @param language filter by passed language
91
   * @param status optionalvacation request status
92
   */
93
  getVacationRequestsWithLanguage(language: Languages, status?: string) {
94
    return this.makeGetVacationRequestsApiCall(language, status);
95
  }
96

    
97

    
98
  /**
99
   * Returns all authorization requests
100
   * @param status optional authorization request status
101
   */
102
  getAuthorizationRequests(status?: string) {
103
    return this.makeGetAuthorizationRequestsApiCall(null, status);
104
  }
105

    
106

    
107
  /**
108
   * Returns authorization requests filtered by language
109
   * @param language filter by passed language
110
   * @param status optional authorization request status
111
   */
112
  getAuthorizationRequestsWithLanguage(language: Languages, status?: string) {
113
    return this.makeGetAuthorizationRequestsApiCall(language, status);
114
  }
115

    
116
  /**
117
   * Získání žádostí o autorizaci všech uživatelů s možností filtrace pomocí úrovně schválení.
118
   * GET /users/requests/authorization?[lang=<CZ,EN>]&[status=<ACCEPTED, PENDING, REJECTED>
119
   * @param language filter by language
120
   * @param status optional authorization request status
121
   */
122
  private makeGetAuthorizationRequestsApiCall(language?: string, statusReq?: string) {
123
    const httpParams: HttpParams = this.createParams({lang: language, status: statusReq});
124
    const options = {params: httpParams};
125

    
126
    return this.http.get<AuthorizationRequest[]>(this._usersUrl + '/requests/authorization', options)
127
      .pipe(
128
        catchError(err => this.handleError(err))
129
      );
130
  }
131

    
132
  /**
133
   * Získání žádostí o dovolené a sick days všech uživatelů s možností filtrace pomocí úrovně schválení.
134
   * GET /users/requests/vacation? [lang=<CZ,EN>]&[status=<ACCEPTED, PENDING, REJECTED>]
135
   * @param language filter by language
136
   * @param status vacation request status
137
   */
138
  private makeGetVacationRequestsApiCall(language?: string, statusReq?: string) {
139
    const httpParams: HttpParams = this.createParams({lang: language, status: statusReq});
140
    const options = {params: httpParams};
141

    
142
    return this.http.get<VacationRequest[]>(this._usersUrl + '/requests/vacation', options)
143
      .pipe(
144
        catchError(err => this.handleError(err))
145
      );
146
  }
147

    
148
  /**
149
   * Získání všech uživatelů s možností filtrace pomocí statusu
150
   * GET /users?[lang=<CZ,EN>]&[status=<ACCEPTED, PENDING, REJECTED>]
151
   * @param status filter by status
152
   * @param language filter by language
153
   */
154
  private makeGetUsersApiCall(language?: string, status?: string): Observable<UserBasicInformation[]> {
155
    const httpParams: HttpParams = this.createParams({lang: language, status});
156
    const options = {params: httpParams};
157

    
158
    return this.http.get<UserBasicInformation[]>(this._usersUrl, options)
159
      .pipe(
160
        catchError(err => this.handleError(err))
161
      );
162
  }
163

    
164
}
(5-5/5)