Projekt

Obecné

Profil

Stáhnout (7.18 KB) Statistiky
| Větev: | Tag: | Revize:
1 84a8db02 Hung Hoang
import {Injectable} from '@angular/core';
2 4bcef705 Hung Hoang
import {HttpClient, HttpParams} from '@angular/common/http';
3 84a8db02 Hung Hoang
import {BasicService} from './basic.service';
4 79d7de40 Hung Hoang
import {catchError} from 'rxjs/operators';
5 41741550 Hung Hoang
6 fd5ab42e Hung Hoang
import {AuthorizationRequest, VacationRequest} from '../../models/requests.model';
7
import {Languages, ProfileStatus} from '../../enums/common.enum';
8 c40c10c6 Hung Hoang
import {Observable} from 'rxjs';
9 d2799ca5 Jakub Danek
import {UserBasicInformation, UserProfile} from '../../models/user.model';
10 1d169f6d Hung Hoang
import {MatSnackBar} from '@angular/material';
11 5d32cbea Václav Jirák
import {TranslateService} from '@ngx-translate/core';
12 41741550 Hung Hoang
13
@Injectable({
14
  providedIn: 'root'
15
})
16
export class UsersService extends BasicService {
17 4bcef705 Hung Hoang
  private _usersUrl = this.baseUrl + '/api/users';
18
19 5d32cbea Václav Jirák
  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) {
20
    super(http, snackBar, translateService);
21 4bcef705 Hung Hoang
  }
22 41741550 Hung Hoang
23 d2799ca5 Jakub Danek
  /**
24
   * Returns profile of currently logged user
25
   * UserProfile.notification might be returned as string instead of date
26
   */
27
  getLoggedUserProfile() {
28
    return this.makeGetProfileApiCall('current', null);
29
  }
30
31
  /**
32
   * Returns profile of currently logged user filtered by language
33
   * UserProfile.notification might be returned as string instead of date
34
   * @param language filter profile by language
35
   */
36
  getLoggedUserProfileWithLanguage(language: Languages) {
37
    return this.makeGetProfileApiCall('current', language);
38
  }
39
40
  /**
41
   * Returns user profile if the user making this call
42
   * is logged as admin
43
   * UserProfile.notification might be returned as string instead of date
44
   * @param id user profile id
45
   */
46
  getUserProfile(id: number) {
47
    return this.makeGetProfileApiCall(id.toString(), null);
48
  }
49
50
  /**
51
   * Overloaded version of getUserProfile to filter profiles
52
   * by language
53
   * UserProfile.notification might be returned as string instead of date
54
   * @param id user profile id
55
   * @param language language to filtery by
56
   */
57
  getUserProfileWithLanguage(id: number, language: Languages) {
58
    return this.makeGetProfileApiCall(id.toString(), language);
59
  }
60
61 84a8db02 Hung Hoang
  /**
62
   * Returns all authorized users
63
   */
64 41741550 Hung Hoang
  getAuthorizedUsers() {
65 7479e470 Hung Hoang
    return this.makeGetUsersApiCall(null, ProfileStatus.AUTHORIZED);
66 41741550 Hung Hoang
  }
67
68 84a8db02 Hung Hoang
  /**
69
   * Returns all authorized users with specified language
70
   * overloaded version of getAuthorizedUsers
71
   * @param language filter users based on language
72
   */
73
  getAuthorizedUsersWithLanguage(language: Languages) {
74 7479e470 Hung Hoang
    return this.makeGetUsersApiCall(language, ProfileStatus.AUTHORIZED);
75 84a8db02 Hung Hoang
  }
76
77
  /**
78
   * Returns all pending users
79
   */
80 41741550 Hung Hoang
  getPendingUsers() {
81 7479e470 Hung Hoang
    return this.makeGetUsersApiCall(null, ProfileStatus.PENDING);
82 84a8db02 Hung Hoang
  }
83
84
  /**
85
   * Returns all pending users with specified language
86
   * overloaded version of getPendingUsers
87
   * @param language filter users based on language
88
   */
89
  getPendingUsersWithLanguage(language: Languages) {
90 7479e470 Hung Hoang
    return this.makeGetUsersApiCall(language, ProfileStatus.PENDING);
91 41741550 Hung Hoang
  }
92
93 84a8db02 Hung Hoang
  /**
94
   * Return all rejected users
95
   */
96 41741550 Hung Hoang
  getRejectedUsers() {
97 7479e470 Hung Hoang
    return this.makeGetUsersApiCall(null, ProfileStatus.REJECTED);
98 41741550 Hung Hoang
  }
99
100 84a8db02 Hung Hoang
  /**
101
   * Returns all rejected users with specified language
102
   * overloaded version of getRejectedUsers
103
   * @param language filter users based on language
104
   */
105
  getRejectedUsersWithLanguage(language: Languages) {
106 7479e470 Hung Hoang
    return this.makeGetUsersApiCall(language, ProfileStatus.REJECTED);
107 84a8db02 Hung Hoang
  }
108
109
 /**
110
  * Default api call which returns all users in the database
111
  * regardless of language and status
112
  */
113
  getUsers() {
114 7479e470 Hung Hoang
    return this.makeGetUsersApiCall();
115 41741550 Hung Hoang
  }
116
117 84a8db02 Hung Hoang
  /**
118 7479e470 Hung Hoang
   * Returns all vacation requests specified by status, if status
119
   * is not specified, returns all vacation requests
120
   * @param status optional vacation request status
121 84a8db02 Hung Hoang
   */
122 7479e470 Hung Hoang
  getVacationRequests(status?: string) {
123
    return this.makeGetVacationRequestsApiCall( null, status);
124 84a8db02 Hung Hoang
  }
125
126
  /**
127
   * Returns vacations filtered by language
128
   * @param language filter by passed language
129 7479e470 Hung Hoang
   * @param status optionalvacation request status
130 84a8db02 Hung Hoang
   */
131 7479e470 Hung Hoang
  getVacationRequestsWithLanguage(language: Languages, status?: string) {
132
    return this.makeGetVacationRequestsApiCall(language, status);
133 41741550 Hung Hoang
  }
134
135 84a8db02 Hung Hoang
136
  /**
137
   * Returns all authorization requests
138 7479e470 Hung Hoang
   * @param status optional authorization request status
139 84a8db02 Hung Hoang
   */
140 7479e470 Hung Hoang
  getAuthorizationRequests(status?: string) {
141
    return this.makeGetAuthorizationRequestsApiCall(null, status);
142 84a8db02 Hung Hoang
  }
143
144
145
  /**
146
   * Returns authorization requests filtered by language
147
   * @param language filter by passed language
148 7479e470 Hung Hoang
   * @param status optional authorization request status
149 84a8db02 Hung Hoang
   */
150 7479e470 Hung Hoang
  getAuthorizationRequestsWithLanguage(language: Languages, status?: string) {
151
    return this.makeGetAuthorizationRequestsApiCall(language, status);
152 84a8db02 Hung Hoang
  }
153
154 4bcef705 Hung Hoang
  /**
155
   * Získání žádostí o autorizaci všech uživatelů s možností filtrace pomocí úrovně schválení.
156
   * GET /users/requests/authorization?[lang=<CZ,EN>]&[status=<ACCEPTED, PENDING, REJECTED>
157
   * @param language filter by language
158 7479e470 Hung Hoang
   * @param status optional authorization request status
159 4bcef705 Hung Hoang
   */
160 7479e470 Hung Hoang
  private makeGetAuthorizationRequestsApiCall(language?: string, statusReq?: string) {
161
    const httpParams: HttpParams = this.createParams({lang: language, status: statusReq});
162 4bcef705 Hung Hoang
    const options = {params: httpParams};
163 84a8db02 Hung Hoang
164 4bcef705 Hung Hoang
    return this.http.get<AuthorizationRequest[]>(this._usersUrl + '/requests/authorization', options)
165 84a8db02 Hung Hoang
      .pipe(
166
        catchError(err => this.handleError(err))
167
      );
168
  }
169
170 4bcef705 Hung Hoang
  /**
171
   * Získání žádostí o dovolené a sick days všech uživatelů s možností filtrace pomocí úrovně schválení.
172
   * GET /users/requests/vacation? [lang=<CZ,EN>]&[status=<ACCEPTED, PENDING, REJECTED>]
173
   * @param language filter by language
174 7479e470 Hung Hoang
   * @param status vacation request status
175 4bcef705 Hung Hoang
   */
176 7479e470 Hung Hoang
  private makeGetVacationRequestsApiCall(language?: string, statusReq?: string) {
177
    const httpParams: HttpParams = this.createParams({lang: language, status: statusReq});
178 4bcef705 Hung Hoang
    const options = {params: httpParams};
179 84a8db02 Hung Hoang
180 4bcef705 Hung Hoang
    return this.http.get<VacationRequest[]>(this._usersUrl + '/requests/vacation', options)
181 84a8db02 Hung Hoang
      .pipe(
182
        catchError(err => this.handleError(err))
183
      );
184 41741550 Hung Hoang
  }
185
186 4bcef705 Hung Hoang
  /**
187
   * Získání všech uživatelů s možností filtrace pomocí statusu
188
   * GET /users?[lang=<CZ,EN>]&[status=<ACCEPTED, PENDING, REJECTED>]
189
   * @param status filter by status
190
   * @param language filter by language
191
   */
192 7479e470 Hung Hoang
  private makeGetUsersApiCall(language?: string, status?: string): Observable<UserBasicInformation[]> {
193 4bcef705 Hung Hoang
    const httpParams: HttpParams = this.createParams({lang: language, status});
194
    const options = {params: httpParams};
195 84a8db02 Hung Hoang
196 4bcef705 Hung Hoang
    return this.http.get<UserBasicInformation[]>(this._usersUrl, options)
197 41741550 Hung Hoang
      .pipe(
198
        catchError(err => this.handleError(err))
199
      );
200
  }
201
202 d2799ca5 Jakub Danek
  /**
203
   * Získání profilu aktuálně přihlášeného uživatele nebo uživatele podle zadaného id.
204
   * GET /user/<{id} || me>/profile?[lang=<CZ,EN>]
205
   * @param id id of profile to get (number or 'me')
206
   * @param language filter by language
207
   */
208
  private makeGetProfileApiCall(id: string, language: string) {
209
    const httpParams: HttpParams = this.createParams({lang: language});
210
    const options = {params: httpParams};
211
212
    return this.http.get<UserProfile>(this._usersUrl + "/" + id + '/profile', options)
213
      .pipe(
214
        catchError(err => this.handleError(err))
215
      );
216
  }
217
218
219 41741550 Hung Hoang
}