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