1 |
41741550
|
Hung Hoang
|
import { Injectable } from '@angular/core';
|
2 |
|
|
import { HttpClient } from '@angular/common/http';
|
3 |
|
|
|
4 |
|
|
import { UserProfile } from '../models/user-profile.model';
|
5 |
|
|
import { Calendar } from '../models/calendar.model';
|
6 |
|
|
import { BasicService } from './basic.service';
|
7 |
|
|
import { catchError } from 'rxjs/operators';
|
8 |
|
|
import {RequestTypes, TimeUnit} from '../enums/common.enum';
|
9 |
|
|
import {PostRequest, PostSettings} from '../models/post-requests.model';
|
10 |
|
|
|
11 |
|
|
@Injectable({
|
12 |
|
|
providedIn: 'root'
|
13 |
|
|
})
|
14 |
|
|
export class UserService extends BasicService { // dost podobny k usersService, mozna zmenit v rest api
|
15 |
|
|
private calendarUrl = this.baseUrl + '/user/calendar';
|
16 |
|
|
private postRequestUrl = this.baseUrl + '/user/requests?type=';
|
17 |
|
|
private userUrl = this.baseUrl + '/user/';
|
18 |
|
|
|
19 |
|
|
getEmployeeProfile(id: number) { // najit jinej zpusob formatovani stringu, prasarna
|
20 |
b919891c
|
Hung Hoang
|
return this.http.get<UserProfile>(this.userUrl + id + '/profile');
|
21 |
41741550
|
Hung Hoang
|
}
|
22 |
|
|
|
23 |
|
|
getMonthlyCalendar(value: number) {
|
24 |
|
|
return this.getCalendar(TimeUnit.MONTHLY, value);
|
25 |
|
|
}
|
26 |
|
|
|
27 |
|
|
getWeeklyCalendar(value: number) {
|
28 |
|
|
return this.getCalendar(TimeUnit.WEEKLY, value);
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
private getCalendar(viewType: string, value: number) {
|
32 |
|
|
return this.http.get<Calendar[]>(this.calendarUrl + '?viewType=' + viewType + '&value=' + value)
|
33 |
|
|
.pipe(
|
34 |
|
|
catchError(err => this.handleError(err))
|
35 |
|
|
);
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
postCalendar(calendar: Calendar[]) {
|
39 |
|
|
return this.postCalendarWithOptions(calendar, {});
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
postCalendarWithResponse(calendar: Calendar[]) {
|
43 |
|
|
return this.postCalendarWithOptions(calendar, {observe: 'response'});
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
private postCalendarWithOptions(calendar: Calendar[], options: any) {
|
47 |
|
|
return this.http.post<Calendar[]>(this.calendarUrl, calendar, options)
|
48 |
|
|
.pipe(
|
49 |
|
|
catchError(err => this.handleError(err))
|
50 |
|
|
);
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
postVacationRequest(request: PostRequest) {
|
54 |
|
|
return this.postRequestWithTypeAndOptions(request, RequestTypes.VACATION, {});
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
postVacationRequestWithResponse(request: PostRequest) {
|
58 |
|
|
return this.postRequestWithTypeAndOptions(request, RequestTypes.VACATION, {observe: 'response'});
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
postAuthorizationRequest(request: PostRequest) {
|
62 |
|
|
return this.postRequestWithTypeAndOptions(request, RequestTypes.AUTHORIZATION, {});
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
postAuthorizationRequestWithResponse(request: PostRequest) {
|
66 |
|
|
return this.postRequestWithTypeAndOptions(request, RequestTypes.AUTHORIZATION, {observe: 'response'});
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
private postRequestWithTypeAndOptions(request: PostRequest, type: string, options: any) {
|
70 |
|
|
return this.http.post<PostRequest>(this.postRequestUrl + type, request, options)
|
71 |
|
|
.pipe(
|
72 |
|
|
catchError(err => this.handleError(err))
|
73 |
|
|
);
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
postUserSettings(id: number, settings: PostSettings) {
|
77 |
|
|
return this.postUserSettingsWithOptions(id, settings, {});
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
postUserSettingsWithResponse(id: number, settings: PostSettings) {
|
81 |
|
|
return this.postUserSettingsWithOptions(id, settings, {observe: 'response'});
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
private postUserSettingsWithOptions(id: number, settings: PostSettings, options: any) {
|
85 |
|
|
return this.http.post<PostSettings>(this.userUrl + id + '/settings', settings, options)
|
86 |
|
|
.pipe(
|
87 |
|
|
catchError(err => this.handleError(err))
|
88 |
|
|
);
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
constructor(protected http: HttpClient) {
|
92 |
|
|
super(http);
|
93 |
|
|
}
|
94 |
|
|
}
|