Revize d2799ca5
Přidáno uživatelem Jakub Danek před více než 5 roky(ů)
webapp/src/app/services/api/user.service.ts | ||
---|---|---|
6 | 6 |
import {catchError} from 'rxjs/operators'; |
7 | 7 |
import {Languages, RequestStatus, RequestTypes} from '../../enums/common.enum'; |
8 | 8 |
import {NotificationSettings, UserSettings} from '../../models/settings.model'; |
9 |
import {UserProfile} from '../../models/user.model'; |
|
10 | 9 |
import {UserRequest} from '../../models/requests.model'; |
11 | 10 |
import {MatSnackBar} from '@angular/material'; |
12 | 11 |
import {DateFormatterService} from '../util/date-formatter.service'; |
... | ... | |
16 | 15 |
providedIn: 'root' |
17 | 16 |
}) |
18 | 17 |
export class UserService extends BasicService { // dost podobny k usersService, mozna zmenit v rest api |
19 |
private _userUrl = this.baseUrl + '/api/user/'; |
|
18 |
private _userUrl = this.baseUrl + '/api/users/';
|
|
20 | 19 |
|
21 | 20 |
constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService, private dateFormater: DateFormatterService) { |
22 | 21 |
super(http, snackBar, translateService); |
23 | 22 |
} |
24 | 23 |
|
25 |
/** |
|
26 |
* Returns user profile if the user making this call |
|
27 |
* is logged as admin |
|
28 |
* UserProfile.notification might be returned as string instead of date |
|
29 |
* @param id user profile id |
|
30 |
*/ |
|
31 |
getUserProfile(id: number) { |
|
32 |
return this.makeGetProfileApiCall(id.toString(), null); |
|
33 |
} |
|
34 |
|
|
35 |
/** |
|
36 |
* Overloaded version of getUserProfile to filter profiles |
|
37 |
* by language |
|
38 |
* UserProfile.notification might be returned as string instead of date |
|
39 |
* @param id user profile id |
|
40 |
* @param language language to filtery by |
|
41 |
*/ |
|
42 |
getUserProfileWithLanguage(id: number, language: Languages) { |
|
43 |
return this.makeGetProfileApiCall(id.toString(), language); |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* Returns profile of currently logged user |
|
48 |
* UserProfile.notification might be returned as string instead of date |
|
49 |
*/ |
|
50 |
getLoggedUserProfile() { |
|
51 |
return this.makeGetProfileApiCall('me', null); |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* Returns profile of currently logged user filtered by language |
|
56 |
* UserProfile.notification might be returned as string instead of date |
|
57 |
* @param language filter profile by language |
|
58 |
*/ |
|
59 |
getLoggedUserProfileWithLanguage(language: Languages) { |
|
60 |
return this.makeGetProfileApiCall('me', language); |
|
61 |
} |
|
62 |
|
|
63 | 24 |
/** |
64 | 25 |
* Returns vacation and sick days from the given date |
65 | 26 |
* for logged user |
... | ... | |
167 | 128 |
return this.makeDeleteCalendarApiCall(id, language); |
168 | 129 |
} |
169 | 130 |
|
170 |
/** |
|
171 |
* Získání profilu aktuálně přihlášeného uživatele nebo uživatele podle zadaného id. |
|
172 |
* GET /user/<{id} || me>/profile?[lang=<CZ,EN>] |
|
173 |
* @param id id of profile to get (number or 'me') |
|
174 |
* @param language filter by language |
|
175 |
*/ |
|
176 |
private makeGetProfileApiCall(id: string, language: string) { |
|
177 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
178 |
const options = {params: httpParams}; |
|
179 |
|
|
180 |
return this.http.get<UserProfile>(this._userUrl + id + '/profile', options) |
|
181 |
.pipe( |
|
182 |
catchError(err => this.handleError(err)) |
|
183 |
); |
|
184 |
} |
|
185 |
|
|
186 | 131 |
/** |
187 | 132 |
* Získání dovolené a sick days v zadaném období. Pokud není zadán parameter “to” vrátí všechny dovolené a sick days od “from”. Navíc umožňuje filtrovat pomocí statusu schválení. |
188 | 133 |
* GET /user/<{id} || me>/calendar?[lang=<CZ,EN>]&from=yyyy/mm/dd, [to=yyyy/mm/dd], [status=<ACCEPTED, PENDING, REJECTED>] |
Také k dispozici: Unified diff
re #37 make UI compatible with new User controller API