Revize 4bcef705
Přidáno uživatelem Hung Hoang před téměř 6 roky(ů)
webapp/src/app/employees/employees-list.component.ts | ||
---|---|---|
66 | 66 |
} |
67 | 67 |
} |
68 | 68 |
|
69 |
|
|
70 |
/** |
|
71 |
* Map from UserBasicInformation model to inner class model User |
|
72 |
*/ |
|
69 | 73 |
private mapUsers(): void { |
70 | 74 |
let user: User; |
71 | 75 |
this._users = []; |
... | ... | |
80 | 84 |
} |
81 | 85 |
} |
82 | 86 |
|
87 |
/** |
|
88 |
* Creates array of days with information about the user's |
|
89 |
* vacation and sick days in range 7 days before and 7 days after |
|
90 |
* @param user one user row with |
|
91 |
*/ |
|
83 | 92 |
private mapDays(user: UserBasicInformation): DayInfo[] { |
84 | 93 |
const dayInfo: DayInfo[] = []; |
85 | 94 |
|
... | ... | |
87 | 96 |
const day: DayInfo = new DayInfo(); |
88 | 97 |
day.type = VacationType.NONE; |
89 | 98 |
|
90 |
for (const vacationDay of user.calendar) { |
|
91 |
const vacationDate: Date = new Date(vacationDay.date); |
|
92 |
|
|
93 |
if (vacationDate.getDate() === date.getDate()) { |
|
94 |
day.type = vacationDay.type; |
|
99 |
for (const calendarDay of user.calendar) { |
|
100 |
if (new Date(calendarDay.date).getDate() === date.getDate()) { |
|
101 |
day.type = calendarDay.type; |
|
95 | 102 |
} |
96 | 103 |
} |
97 | 104 |
|
... | ... | |
105 | 112 |
ngOnInit() { |
106 | 113 |
this.usersService.getAuthorizedUsers() |
107 | 114 |
.subscribe((data: UserBasicInformation[]) => { |
108 |
for (const entry of data) { |
|
109 |
this._employeesBasicInformation.push(entry); |
|
110 |
} |
|
115 |
this._employeesBasicInformation = data; |
|
111 | 116 |
this.mapUsers(); |
112 |
console.log(this._users); |
|
113 | 117 |
}); |
114 | 118 |
|
119 |
// const calendar: PostCalendar = { date: '1999/10/10', from: '15:00', to: '17:00', type: VacationType.VACATION }; |
|
120 |
// this.userService.postCalendar(calendar) |
|
121 |
// .subscribe((data: any) => console.log(data)); |
|
115 | 122 |
|
116 |
let authorization: AuthorizationRequest[]; |
|
117 |
this.usersService.getAuthorizationRequests() |
|
118 |
.subscribe((data: AuthorizationRequest[]) => { |
|
119 |
authorization = { ...data}; |
|
123 |
// const settings: PostUserSettings = { |
|
124 |
// id: 1, |
|
125 |
// role: UserType.EMPLOYEE, |
|
126 |
// sickdayCount: 1, |
|
127 |
// vacationCount: 1, |
|
128 |
// }; |
|
129 |
// |
|
130 |
// this.userService.putUserSettings(settings) |
|
131 |
// .subscribe((data: any) => console.log(data)); |
|
120 | 132 |
|
121 |
console.log(authorization); |
|
122 |
}); |
|
123 | 133 |
} |
124 | 134 |
|
125 | 135 |
} |
webapp/src/app/models/calendar.model.ts | ||
---|---|---|
2 | 2 |
import {RequestStatus, VacationType} from '../enums/common.enum'; |
3 | 3 |
|
4 | 4 |
export interface Calendar { |
5 |
date: Date; |
|
5 |
id: number; |
|
6 |
date: string; |
|
6 | 7 |
from: Time; |
7 | 8 |
to: Time; |
8 | 9 |
type: VacationType; |
9 | 10 |
status: RequestStatus; |
10 | 11 |
} |
12 |
|
|
13 |
|
|
14 |
export interface PostCalendar { |
|
15 |
date: string; |
|
16 |
from: string; |
|
17 |
to: string; |
|
18 |
type: VacationType; |
|
19 |
} |
|
20 |
|
|
21 |
export interface CalendarEdit { |
|
22 |
id: number; |
|
23 |
date: string; |
|
24 |
from: string; |
|
25 |
to: string; |
|
26 |
} |
webapp/src/app/models/post-requests.model.ts | ||
---|---|---|
1 | 1 |
import {RequestStatus, TimeUnit, UserType} from '../enums/common.enum'; |
2 | 2 |
|
3 |
export interface PostRequest {
|
|
3 |
export interface UserRequest {
|
|
4 | 4 |
id: number; |
5 | 5 |
status: RequestStatus; |
6 | 6 |
} |
7 |
|
|
8 |
export interface PostSettings { |
|
9 |
role: UserType; |
|
10 |
vacation: { |
|
11 |
value: number; |
|
12 |
unit: TimeUnit; |
|
13 |
}; |
|
14 |
sickday: { |
|
15 |
value: number; |
|
16 |
unit: TimeUnit; |
|
17 |
}; |
|
18 |
} |
webapp/src/app/models/settings.model.ts | ||
---|---|---|
1 |
import {UserType} from '../enums/common.enum'; |
|
2 |
|
|
1 | 3 |
export interface Settings { |
2 |
sickDay: { |
|
3 |
value: number; |
|
4 |
unit: string; |
|
5 |
}; |
|
6 |
notification: Date; |
|
4 |
sickdayCount: number; |
|
5 |
notification: string; |
|
7 | 6 |
} |
7 |
|
|
8 |
export interface PostUserSettings { |
|
9 |
id: number; |
|
10 |
vacationCount: number; |
|
11 |
sickdayCount: number; |
|
12 |
role: UserType; |
|
13 |
} |
|
14 |
|
webapp/src/app/models/user-profile.model.ts | ||
---|---|---|
1 |
import {TimeUnit} from '../enums/common.enum';
|
|
1 |
import {RequestStatus, UserType} from '../enums/common.enum';
|
|
2 | 2 |
|
3 | 3 |
export interface UserProfile { |
4 | 4 |
id: number; |
5 |
name: { |
|
6 |
first: string; |
|
7 |
last: string; |
|
8 |
}; |
|
5 |
firstName: string; |
|
6 |
lastName: string; |
|
9 | 7 |
photo: string; |
10 |
settings: { |
|
11 |
notification: Date; |
|
12 |
}; |
|
13 |
vacation: { |
|
14 |
value: number; |
|
15 |
unit: TimeUnit; |
|
16 |
}; |
|
17 |
sickDay: { |
|
18 |
value: number; |
|
19 |
unit: TimeUnit; |
|
20 |
}; |
|
8 |
vacationCount: number; |
|
9 |
sickdayCount: number; |
|
10 |
status: RequestStatus; |
|
11 |
role: UserType; |
|
12 |
notification: Date; |
|
21 | 13 |
} |
22 | 14 |
|
webapp/src/app/services/basic.service.ts | ||
---|---|---|
1 |
import { Injectable } from '@angular/core';
|
|
2 |
import {HttpClient, HttpErrorResponse, HttpHeaders} from '@angular/common/http';
|
|
1 |
import {Injectable} from '@angular/core';
|
|
2 |
import {HttpClient, HttpErrorResponse, HttpParams} from '@angular/common/http';
|
|
3 | 3 |
import {throwError} from 'rxjs'; |
4 | 4 |
import {environment} from '../../environments/environment'; |
5 | 5 |
|
... | ... | |
9 | 9 |
export class BasicService { |
10 | 10 |
protected baseUrl = environment.apiUrl; |
11 | 11 |
|
12 |
constructor(protected http: HttpClient) { } |
|
13 |
|
|
12 | 14 |
protected handleError(error: HttpErrorResponse) { |
13 | 15 |
if (error.error instanceof ErrorEvent) { |
14 | 16 |
console.error('An error occurred:', error.error.message); |
... | ... | |
21 | 23 |
'Something bad happened; please try again later.'); |
22 | 24 |
} |
23 | 25 |
|
24 |
constructor(protected http: HttpClient) { } |
|
26 |
protected createParams(params: any) { |
|
27 |
let httpParams = new HttpParams(); |
|
28 |
for (const key in params) { |
|
29 |
if (params.hasOwnProperty(key)) { |
|
30 |
if (params[key] != null) { |
|
31 |
httpParams = httpParams.set(key, params[key]); |
|
32 |
} |
|
33 |
} |
|
34 |
} |
|
35 |
|
|
36 |
return httpParams; |
|
37 |
} |
|
25 | 38 |
} |
webapp/src/app/services/settings.service.spec.ts | ||
---|---|---|
1 |
import {TestBed} from '@angular/core/testing'; |
|
2 |
|
|
3 |
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing'; |
|
4 |
import {environment} from '../../environments/environment'; |
|
5 |
import {SettingsService} from './settings.service'; |
|
6 |
import {Languages} from '../enums/common.enum'; |
|
7 |
|
|
8 |
describe('SettingsService', () => { |
|
9 |
let service: SettingsService; |
|
10 |
let httpMock: HttpTestingController; |
|
11 |
const baseUrl: string = environment.apiUrl; |
|
12 |
|
|
13 |
beforeEach(() => { |
|
14 |
TestBed.configureTestingModule({ |
|
15 |
imports: [HttpClientTestingModule], |
|
16 |
providers: [SettingsService] |
|
17 |
}); |
|
18 |
|
|
19 |
service = TestBed.get(SettingsService); |
|
20 |
httpMock = TestBed.get(HttpTestingController); |
|
21 |
}); |
|
22 |
afterEach(() => httpMock.verify()); |
|
23 |
|
|
24 |
it('getDefaultSettings', () => { |
|
25 |
const dummyData = { |
|
26 |
sickdayCount: 3, |
|
27 |
notification: '2019/05/25 14:41:31' |
|
28 |
}; |
|
29 |
|
|
30 |
service.getDefaultSettings().subscribe((data: any) => { |
|
31 |
expect(data.sickdayCount).toBeDefined(); |
|
32 |
expect(data.sickdayCount).toBe(3); |
|
33 |
expect(data.notification).toBeDefined(); |
|
34 |
}); |
|
35 |
|
|
36 |
const req = httpMock.expectOne(baseUrl + '/api/settings'); |
|
37 |
expect(req.request.method).toBe('GET'); |
|
38 |
req.flush(dummyData); |
|
39 |
}); |
|
40 |
|
|
41 |
it('getDefaultSettingsWithLanguage', () => { |
|
42 |
const dummyData = { |
|
43 |
sickdayCount: 3, |
|
44 |
notification: '2019/05/25 14:41:31' |
|
45 |
}; |
|
46 |
|
|
47 |
service.getDefaultSettingsWithLanguage(Languages.ENGLISH).subscribe((data: any) => { |
|
48 |
expect(data.sickdayCount).toBeDefined(); |
|
49 |
expect(data.sickdayCount).toBe(3); |
|
50 |
expect(data.notification).toBeDefined(); |
|
51 |
}); |
|
52 |
|
|
53 |
const req = httpMock.expectOne(baseUrl + '/api/settings?lang=EN'); |
|
54 |
expect(req.request.method).toBe('GET'); |
|
55 |
req.flush(dummyData); |
|
56 |
}); |
|
57 |
|
|
58 |
|
|
59 |
it('postDefaultSettings', () => { |
|
60 |
const dummyAnswer = { |
|
61 |
answer: 'ok', |
|
62 |
}; |
|
63 |
|
|
64 |
service.postDefaultSettings({sickdayCount: 3, notification: '2019/04/25 18:23:36'}) |
|
65 |
.subscribe((data: any) => expect(data.answer).toBe('ok')); |
|
66 |
|
|
67 |
const req = httpMock.expectOne(baseUrl + '/api/settings'); |
|
68 |
expect(req.request.method).toBe('POST'); |
|
69 |
req.flush(dummyAnswer); |
|
70 |
}); |
|
71 |
|
|
72 |
it('postDefaultSettingsWithLanguage', () => { |
|
73 |
const dummyAnswer = { |
|
74 |
answer: 'ok', |
|
75 |
}; |
|
76 |
|
|
77 |
service.postDefaultSettingsWithLanguage({sickdayCount: 3, notification: '2019/04/25 18:23:36'}, Languages.ENGLISH) |
|
78 |
.subscribe((data: any) => expect(data.answer).toBe('ok')); |
|
79 |
|
|
80 |
const req = httpMock.expectOne(baseUrl + '/api/settings?lang=EN'); |
|
81 |
expect(req.request.method).toBe('POST'); |
|
82 |
req.flush(dummyAnswer); |
|
83 |
}); |
|
84 |
|
|
85 |
}); |
webapp/src/app/services/settings.service.ts | ||
---|---|---|
1 | 1 |
import { Injectable } from '@angular/core'; |
2 |
import { HttpClient } from '@angular/common/http';
|
|
2 |
import {HttpClient, HttpParams} from '@angular/common/http';
|
|
3 | 3 |
import { catchError } from 'rxjs/operators'; |
4 | 4 |
|
5 | 5 |
import { BasicService } from './basic.service'; |
6 | 6 |
import { Settings } from '../models/settings.model'; |
7 |
import {Languages} from '../enums/common.enum'; |
|
7 | 8 |
|
8 | 9 |
@Injectable({ |
9 | 10 |
providedIn: 'root' |
10 | 11 |
}) |
11 | 12 |
export class SettingsService extends BasicService { |
12 |
defaultSettingsUrl = this.baseUrl + '/settings/default';
|
|
13 |
defaultSettingsUrl = this.baseUrl + '/api/settings';
|
|
13 | 14 |
|
15 |
constructor(protected http: HttpClient) { |
|
16 |
super(http); |
|
17 |
} |
|
18 |
|
|
19 |
/** |
|
20 |
* Returns default application settings |
|
21 |
* with sickday count and notification |
|
22 |
*/ |
|
14 | 23 |
getDefaultSettings() { |
15 |
return this.http.get<Settings>(this.defaultSettingsUrl) |
|
24 |
return this.makeGetSettingsApiCall(null); |
|
25 |
} |
|
26 |
|
|
27 |
/** |
|
28 |
* Returns default application settings |
|
29 |
* with sickday count and notification |
|
30 |
* @param language filter by language |
|
31 |
*/ |
|
32 |
getDefaultSettingsWithLanguage(language: Languages) { |
|
33 |
return this.makeGetSettingsApiCall(language); |
|
34 |
} |
|
35 |
|
|
36 |
/** |
|
37 |
* Získání aktuálně použitého výchozího nastavení v aplikaci |
|
38 |
* GET /setttings?[lang=<CZ,EN>] |
|
39 |
* @param language filter with language |
|
40 |
*/ |
|
41 |
private makeGetSettingsApiCall(language: string) { |
|
42 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
43 |
const options = {params: httpParams}; |
|
44 |
|
|
45 |
return this.http.get<Settings>(this.defaultSettingsUrl, options) |
|
16 | 46 |
.pipe( |
17 | 47 |
catchError(err => this.handleError(err)) |
18 | 48 |
); |
19 | 49 |
} |
20 | 50 |
|
21 |
postDefaultSettingsWithResponse(settings: Settings) {
|
|
22 |
return this.postDefaultSettingsWithOptions(settings, {observe: 'response'});
|
|
51 |
postDefaultSettings(settings: Settings) { |
|
52 |
return this.postDefaultSettingsWithOptions(settings, null);
|
|
23 | 53 |
} |
24 | 54 |
|
25 |
postDefaultSettings(settings: Settings) {
|
|
26 |
return this.postDefaultSettingsWithOptions(settings, {});
|
|
55 |
postDefaultSettingsWithLanguage(settings: Settings, language: Languages) {
|
|
56 |
return this.postDefaultSettingsWithOptions(settings, language);
|
|
27 | 57 |
} |
28 | 58 |
|
29 |
private postDefaultSettingsWithOptions(settings: Settings, options: any) { |
|
59 |
private postDefaultSettingsWithOptions(settings: Settings, language: Languages) { |
|
60 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
61 |
const options = {params: httpParams}; |
|
62 |
|
|
30 | 63 |
return this.http.post<Settings>(this.defaultSettingsUrl, settings, options) |
31 | 64 |
.pipe( |
32 | 65 |
catchError(err => this.handleError(err)) |
33 | 66 |
); |
34 | 67 |
} |
35 |
|
|
36 |
constructor(protected http: HttpClient) { |
|
37 |
super(http); |
|
38 |
} |
|
39 | 68 |
} |
webapp/src/app/services/user.service.spec.ts | ||
---|---|---|
1 |
import {TestBed} from '@angular/core/testing'; |
|
2 |
|
|
3 |
import {UserService} from './user.service'; |
|
4 |
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing'; |
|
5 |
import {Languages, RequestStatus, UserType, VacationType} from '../enums/common.enum'; |
|
6 |
import {environment} from '../../environments/environment'; |
|
7 |
|
|
8 |
describe('UsersService', () => { |
|
9 |
let service: UserService; |
|
10 |
let httpMock: HttpTestingController; |
|
11 |
const baseUrl: string = environment.apiUrl; |
|
12 |
|
|
13 |
beforeEach(() => { |
|
14 |
TestBed.configureTestingModule({ |
|
15 |
imports: [HttpClientTestingModule], |
|
16 |
providers: [UserService] |
|
17 |
}); |
|
18 |
|
|
19 |
service = TestBed.get(UserService); |
|
20 |
httpMock = TestBed.get(HttpTestingController); |
|
21 |
}); |
|
22 |
afterEach(() => httpMock.verify()); |
|
23 |
|
|
24 |
it('getLoggedUser', () => { |
|
25 |
const dummyData = { |
|
26 |
id: 1, |
|
27 |
firstName: 'Tomas', |
|
28 |
lastName: 'Novak', |
|
29 |
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg', |
|
30 |
vacationCount: 8.5, |
|
31 |
sickdayCount: 3, |
|
32 |
status: 'ACCEPTED', |
|
33 |
role: 'EMPLOYER', |
|
34 |
notification: '2000/12/01 09:00:00' |
|
35 |
}; |
|
36 |
|
|
37 |
|
|
38 |
service.getLoggedUserProfile().subscribe((data: any) => { |
|
39 |
expect(data.id).toBe(1); |
|
40 |
expect(data.vacationCount).toBe(8.5); |
|
41 |
expect(data.sickdayCount).toBe(3); |
|
42 |
expect(data.status).toBe(RequestStatus.ACCEPTED); |
|
43 |
expect(data.role).toBe(UserType.EMPLOYER); |
|
44 |
expect(data.notification).toBeDefined(); |
|
45 |
}); |
|
46 |
|
|
47 |
const req = httpMock.expectOne(baseUrl + '/api/user/me/profile'); |
|
48 |
expect(req.request.method).toBe('GET'); |
|
49 |
req.flush(dummyData); |
|
50 |
}); |
|
51 |
|
|
52 |
it('getLoggedUserWithLanguage', () => { |
|
53 |
const dummyData = { |
|
54 |
id: 1, |
|
55 |
firstName: 'Tomas', |
|
56 |
lastName: 'Novak', |
|
57 |
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg', |
|
58 |
vacationCount: 8.5, |
|
59 |
sickdayCount: 3, |
|
60 |
status: 'ACCEPTED', |
|
61 |
role: 'EMPLOYER', |
|
62 |
notification: '2000/12/01 09:00:00' |
|
63 |
}; |
|
64 |
|
|
65 |
|
|
66 |
service.getLoggedUserProfileWithLanguage(Languages.ENGLISH).subscribe((data: any) => { |
|
67 |
expect(data.id).toBe(1); |
|
68 |
expect(data.vacationCount).toBe(8.5); |
|
69 |
expect(data.sickdayCount).toBe(3); |
|
70 |
expect(data.status).toBe(RequestStatus.ACCEPTED); |
|
71 |
expect(data.role).toBe(UserType.EMPLOYER); |
|
72 |
expect(data.notification).toBeDefined(); |
|
73 |
}); |
|
74 |
|
|
75 |
const req = httpMock.expectOne(baseUrl + '/api/user/me/profile?lang=EN'); |
|
76 |
expect(req.request.method).toBe('GET'); |
|
77 |
req.flush(dummyData); |
|
78 |
}); |
|
79 |
|
|
80 |
it('getLoggedUserCalendar', () => { |
|
81 |
const dummyData = [ |
|
82 |
{id: 1, date: '2000/10/10', from: '09:00', to: '13:00', type: 'VACATION'}, |
|
83 |
{id: 2, date: '2000/10/11', type: 'SICKDAY'}, |
|
84 |
{id: 3, date: '2000/10/12', from: '09:00', to: '13:00', type: 'VACATION'}, |
|
85 |
{id: 4, date: '2000/10/13', type: 'SICKDAY'}, |
|
86 |
{id: 5, date: '2000/10/14', from: '09:00', to: '13:00', type: 'VACATION'} |
|
87 |
]; |
|
88 |
|
|
89 |
service.getLoggedUserCalendar(new Date(1995, 10, 25)) |
|
90 |
.subscribe((data: any) => { |
|
91 |
expect(data.length).toBe(5); |
|
92 |
expect(data[1].type).toBe(VacationType.SICKDAY); |
|
93 |
expect(data[2].type).toBe(VacationType.VACATION); |
|
94 |
expect(data[2].from).toBeDefined(); |
|
95 |
expect(data[2].to).toBeDefined(); |
|
96 |
}); |
|
97 |
|
|
98 |
const req = httpMock.expectOne(baseUrl + '/api/user/me/calendar?from=1995/10/25'); |
|
99 |
expect(req.request.method).toBe('GET'); |
|
100 |
req.flush(dummyData); |
|
101 |
}); |
|
102 |
|
|
103 |
it('getLoggedUserCalendarWithOptions', () => { |
|
104 |
const dummyData = [ |
|
105 |
{id: 1, date: '2000/10/10', from: '09:00', to: '13:00', type: 'VACATION', status: 'ACCEPTED'}, |
|
106 |
{id: 2, date: '2000/10/11', type: 'SICKDAY', status: 'ACCEPTED'}, |
|
107 |
{id: 3, date: '2000/10/12', from: '09:00', to: '13:00', type: 'VACATION', status: 'ACCEPTED'}, |
|
108 |
{id: 4, date: '2000/10/13', type: 'SICKDAY', status: 'ACCEPTED'}, |
|
109 |
{id: 5, date: '2000/10/14', from: '09:00', to: '13:00', type: 'VACATION', status: 'ACCEPTED'} |
|
110 |
]; |
|
111 |
|
|
112 |
service.getLoggedUserCalendarWithOptions(new Date(1995, 10, 25), null, null, RequestStatus.ACCEPTED) |
|
113 |
.subscribe((data: any) => { |
|
114 |
expect(data.length).toBe(5); |
|
115 |
expect(data[0].status).toBeDefined(); |
|
116 |
expect(data[0].status).toBe(RequestStatus.ACCEPTED); |
|
117 |
expect(data[1].status).toBe(RequestStatus.ACCEPTED); |
|
118 |
expect(data[2].status).toBe(RequestStatus.ACCEPTED); |
|
119 |
expect(data[3].status).toBe(RequestStatus.ACCEPTED); |
|
120 |
expect(data[4].status).toBe(RequestStatus.ACCEPTED); |
|
121 |
}); |
|
122 |
|
|
123 |
const req = httpMock.expectOne(baseUrl + '/api/user/me/calendar?from=1995/10/25&status=ACCEPTED'); |
|
124 |
expect(req.request.method).toBe('GET'); |
|
125 |
req.flush(dummyData); |
|
126 |
}); |
|
127 |
}); |
webapp/src/app/services/user.service.ts | ||
---|---|---|
1 |
import { Injectable } from '@angular/core';
|
|
2 |
import { HttpClient } from '@angular/common/http';
|
|
1 |
import {Injectable} from '@angular/core';
|
|
2 |
import {HttpClient, HttpParams} from '@angular/common/http';
|
|
3 | 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'; |
|
4 |
import {UserProfile} from '../models/user-profile.model'; |
|
5 |
import {Calendar, CalendarEdit, PostCalendar} from '../models/calendar.model'; |
|
6 |
import {BasicService} from './basic.service'; |
|
7 |
import {catchError} from 'rxjs/operators'; |
|
8 |
import {Languages, RequestStatus} from '../enums/common.enum'; |
|
9 |
import {UserRequest} from '../models/post-requests.model'; |
|
10 |
import {PostUserSettings} from '../models/settings.model'; |
|
10 | 11 |
|
11 | 12 |
@Injectable({ |
12 | 13 |
providedIn: 'root' |
13 | 14 |
}) |
14 | 15 |
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/'; |
|
16 |
private _userUrl = this.baseUrl + '/api/user/'; |
|
18 | 17 |
|
19 |
getEmployeeProfile(id: number) { // najit jinej zpusob formatovani stringu, prasarna
|
|
20 |
return this.http.get<UserProfile>(this._userUrl + id + '/profile');
|
|
18 |
constructor(protected http: HttpClient) {
|
|
19 |
super(http);
|
|
21 | 20 |
} |
22 | 21 |
|
23 |
getMonthlyCalendar(value: number) { |
|
24 |
return this.getCalendar(TimeUnit.MONTHLY, value); |
|
22 |
/** |
|
23 |
* Returns employee profile if the user making this call |
|
24 |
* is logged as admin |
|
25 |
* UserProfile.notification might be returned as string instead of date |
|
26 |
* @param id employee id |
|
27 |
*/ |
|
28 |
getEmployeeProfile(id: number) { |
|
29 |
return this.makeGetProfileApiCall(id.toString(), ''); |
|
25 | 30 |
} |
26 | 31 |
|
27 |
getWeeklyCalendar(value: number) { |
|
28 |
return this.getCalendar(TimeUnit.WEEKLY, value); |
|
32 |
/** |
|
33 |
* Overloaded version of getEmployeeProfile to filter profiles |
|
34 |
* by language |
|
35 |
* UserProfile.notification might be returned as string instead of date |
|
36 |
* @param id employee profile id |
|
37 |
* @param language language to filtery by |
|
38 |
*/ |
|
39 |
getEmployeeProfileWithLanguage(id: number, language: Languages) { |
|
40 |
return this.makeGetProfileApiCall(id.toString(), language); |
|
29 | 41 |
} |
30 | 42 |
|
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 |
); |
|
43 |
/** |
|
44 |
* Returns profile of currently logged user |
|
45 |
* UserProfile.notification might be returned as string instead of date |
|
46 |
*/ |
|
47 |
getLoggedUserProfile() { |
|
48 |
return this.makeGetProfileApiCall('me', null); |
|
36 | 49 |
} |
37 | 50 |
|
38 |
postCalendar(calendar: Calendar[]) { |
|
39 |
return this.postCalendarWithOptions(calendar, {}); |
|
51 |
/** |
|
52 |
* Returns profile of currently logged user filtered by language |
|
53 |
* UserProfile.notification might be returned as string instead of date |
|
54 |
* @param language filter profile by language |
|
55 |
*/ |
|
56 |
getLoggedUserProfileWithLanguage(language: Languages) { |
|
57 |
return this.makeGetProfileApiCall('me', language); |
|
40 | 58 |
} |
41 | 59 |
|
42 |
postCalendarWithResponse(calendar: Calendar[]) { |
|
43 |
return this.postCalendarWithOptions(calendar, {observe: 'response'}); |
|
60 |
/** |
|
61 |
* Returns vacation and sick days from the given date |
|
62 |
* for logged user |
|
63 |
* @param from returns days from this date forward |
|
64 |
*/ |
|
65 |
getLoggedUserCalendar(from: Date) { |
|
66 |
return this.makeGetCalendarApiCall('me', from, null, null, null); |
|
44 | 67 |
} |
45 | 68 |
|
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 |
); |
|
69 |
/** |
|
70 |
* Returns vacation and sick days from the given date |
|
71 |
* for logged user |
|
72 |
* @param from returns days from this date forward |
|
73 |
* @param to limit returned days, returns <from, to> |
|
74 |
* @param language filter by language |
|
75 |
* @param status filter by status |
|
76 |
*/ |
|
77 |
getLoggedUserCalendarWithOptions(from: Date, to: Date, language: Languages, status: RequestStatus) { |
|
78 |
return this.makeGetCalendarApiCall('me', from, to, language, status); |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Post user calendar using POST |
|
83 |
* @param calendar to be posted |
|
84 |
*/ |
|
85 |
postCalendar(calendar: PostCalendar) { |
|
86 |
return this.makePostCalendarApiCall(calendar, null); |
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* Post user calendar using POST with specified language |
|
91 |
* @param calendar to be posted |
|
92 |
* @param language specified language |
|
93 |
*/ |
|
94 |
postCalendarWithLanguage(calendar: PostCalendar, language: Languages) { |
|
95 |
return this.makePostCalendarApiCall(calendar, language); |
|
51 | 96 |
} |
52 | 97 |
|
53 |
postVacationRequest(request: PostRequest) { |
|
54 |
return this.postRequestWithTypeAndOptions(request, RequestTypes.VACATION, {}); |
|
98 |
/** |
|
99 |
* Put user settings with given id for the user |
|
100 |
* @param settings settings to be put |
|
101 |
*/ |
|
102 |
putUserSettings(settings: PostUserSettings) { |
|
103 |
return this.makePutUserSettingsApiCall(settings, null); |
|
55 | 104 |
} |
56 | 105 |
|
57 |
postVacationRequestWithResponse(request: PostRequest) { |
|
58 |
return this.postRequestWithTypeAndOptions(request, RequestTypes.VACATION, {observe: 'response'}); |
|
106 |
/** |
|
107 |
* Put user settings with given id for the user |
|
108 |
* @param settings settings to be put |
|
109 |
* @param language specified language |
|
110 |
*/ |
|
111 |
putUserSettingsWithLanguage(settings: PostUserSettings, language: Languages) { |
|
112 |
return this.makePutUserSettingsApiCall(settings, language); |
|
59 | 113 |
} |
60 | 114 |
|
61 |
postAuthorizationRequest(request: PostRequest) { |
|
62 |
return this.postRequestWithTypeAndOptions(request, RequestTypes.AUTHORIZATION, {}); |
|
115 |
/** |
|
116 |
* Accept or deny user request |
|
117 |
* @param request request to accept or deny |
|
118 |
*/ |
|
119 |
putUserRequest(request: UserRequest) { |
|
120 |
return this.makePutUserRequestApiCall(request, null); |
|
121 |
} |
|
122 |
|
|
123 |
/** |
|
124 |
* Accept or deny user request |
|
125 |
* @param request request to accept or deny |
|
126 |
* @param language specify language |
|
127 |
*/ |
|
128 |
putUserRequestWithLanguage(request: UserRequest, language: Languages) { |
|
129 |
return this.makePutUserRequestApiCall(request, language); |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* Edit calendar |
|
134 |
* @param calendarEdit calendar day to be edited |
|
135 |
* @param language specify language |
|
136 |
*/ |
|
137 |
putCalendarEdit(calendarEdit: CalendarEdit, language: Languages) { |
|
138 |
return this.makePutCalendarEditApiCall(calendarEdit, null); |
|
139 |
} |
|
140 |
|
|
141 |
/** |
|
142 |
* Delete calendar vacation day with given id |
|
143 |
* @param id calendar day id to be deleted |
|
144 |
* @param language specify language |
|
145 |
*/ |
|
146 |
deleteCalendar(id: number, language: Languages) { |
|
147 |
return this.makeDeleteCalendarApiCall(id, language); |
|
148 |
} |
|
149 |
|
|
150 |
/** |
|
151 |
* Získání profilu aktuálně přihlášeného uživatele nebo uživatele podle zadaného id. |
|
152 |
* GET /user/<{id} || me>/profile?[lang=<CZ,EN>] |
|
153 |
* @param id id of profile to get (number or 'me') |
|
154 |
* @param language filter by language |
|
155 |
*/ |
|
156 |
private makeGetProfileApiCall(id: string, language: string) { |
|
157 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
158 |
|
|
159 |
const options = {params: httpParams}; |
|
160 |
|
|
161 |
return this.http.get<UserProfile>(this._userUrl + id + '/profile', options) |
|
162 |
.pipe( |
|
163 |
catchError(err => this.handleError(err)) |
|
164 |
); |
|
63 | 165 |
} |
64 | 166 |
|
65 |
postAuthorizationRequestWithResponse(request: PostRequest) { |
|
66 |
return this.postRequestWithTypeAndOptions(request, RequestTypes.AUTHORIZATION, {observe: 'response'}); |
|
167 |
/** |
|
168 |
* 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í. |
|
169 |
* GET /user/<{id} || me>/calendar?[lang=<CZ,EN>]&from=yyyy/mm/dd, [to=yyyy/mm/dd], [status=<ACCEPTED, PENDING, REJECTED>] |
|
170 |
* @param id id of calendar to get (number or 'me') |
|
171 |
* @param from mandatory param |
|
172 |
* @param to upper limit of days |
|
173 |
* @param language filter by language |
|
174 |
* @param status filter by status |
|
175 |
*/ |
|
176 |
private makeGetCalendarApiCall(id: string, from: Date, to: Date, language: Languages, status: RequestStatus) { |
|
177 |
const fromString: string = from.getFullYear() + '/' + from.getMonth() + '/' + from.getDate(); |
|
178 |
let toString: string; |
|
179 |
if (to != null) { |
|
180 |
toString = to.getFullYear() + '/' + to.getMonth() + '/' + to.getDate(); |
|
181 |
} |
|
182 |
|
|
183 |
const httpParams: HttpParams = this.createParams({lang: language, from: fromString, to: toString, status}); |
|
184 |
const options = {params: httpParams}; |
|
185 |
|
|
186 |
return this.http.get<Calendar[]>(this._userUrl + id + '/calendar', options) |
|
187 |
.pipe( |
|
188 |
catchError(err => this.handleError(err)) |
|
189 |
); |
|
67 | 190 |
} |
68 | 191 |
|
69 |
private postRequestWithTypeAndOptions(request: PostRequest, type: string, options: any) { |
|
70 |
return this.http.post<PostRequest>(this._postRequestUrl + type, request, options) |
|
192 |
/** |
|
193 |
* Povolení nebo zamítnutí žádosti nebo “smazání“ uživatele (změna statusu na REJECTED) |
|
194 |
* PUT /user/requests?[lang=<CZ,EN>]&type=<VACATION, AUTHORIZATION> |
|
195 |
* @param request request to accept or reject |
|
196 |
* @param language specify language |
|
197 |
*/ |
|
198 |
private makePutUserRequestApiCall(request: UserRequest, language: Languages) { |
|
199 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
200 |
const options = {params: httpParams}; |
|
201 |
|
|
202 |
return this.http.put<UserRequest>(this._userUrl + 'request', request, options) |
|
71 | 203 |
.pipe( |
72 | 204 |
catchError(err => this.handleError(err)) |
73 | 205 |
); |
74 | 206 |
} |
75 | 207 |
|
76 |
postUserSettings(id: number, settings: PostSettings) { |
|
77 |
return this.postUserSettingsWithOptions(id, settings, {}); |
|
208 |
|
|
209 |
/** |
|
210 |
* Změna nastavení uživatele podle id |
|
211 |
* PUT /user/settings?[lang=<CZ,EN>] |
|
212 |
* @param settings setting to be set for given user |
|
213 |
* @param language specified language |
|
214 |
*/ |
|
215 |
private makePutUserSettingsApiCall(settings: PostUserSettings, language: Languages) { |
|
216 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
217 |
const options = {params: httpParams}; |
|
218 |
|
|
219 |
return this.http.put<PostUserSettings>(this._userUrl + 'settings', settings, options) |
|
220 |
.pipe( |
|
221 |
catchError(err => this.handleError(err)) |
|
222 |
); |
|
78 | 223 |
} |
79 | 224 |
|
80 |
postUserSettingsWithResponse(id: number, settings: PostSettings) { |
|
81 |
return this.postUserSettingsWithOptions(id, settings, {observe: 'response'}); |
|
225 |
/** |
|
226 |
* Vytvoření nové dovolené nebo sick day |
|
227 |
* POST /user/calendar/create?[lang=<CZ,EN>] |
|
228 |
* @param calendar calendar to be posted |
|
229 |
* @param language specified language |
|
230 |
*/ |
|
231 |
private makePostCalendarApiCall(calendar: PostCalendar, language: Languages) { |
|
232 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
233 |
const options = {params: httpParams}; |
|
234 |
|
|
235 |
return this.http.post<PostCalendar>(this._userUrl + 'calendar/create', calendar, options) |
|
236 |
.pipe( |
|
237 |
catchError(err => this.handleError(err)) |
|
238 |
); |
|
239 |
|
|
82 | 240 |
} |
83 | 241 |
|
84 |
private postUserSettingsWithOptions(id: number, settings: PostSettings, options: any) { |
|
85 |
return this.http.post<PostSettings>(this._userUrl + id + '/settings', settings, options) |
|
242 |
/** |
|
243 |
* Smazání dovolené nebo sickday podle jejího id |
|
244 |
* DELETE /calendar/delete?[lang=<CZ,EN>] |
|
245 |
* @param id id of calendar to delete |
|
246 |
* @param language specify language |
|
247 |
*/ |
|
248 |
private makeDeleteCalendarApiCall(id: number, language: Languages) { |
|
249 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
250 |
const options = {params: httpParams}; |
|
251 |
|
|
252 |
return this.http.delete(this._userUrl + 'calendar/delete/' + id, options) |
|
86 | 253 |
.pipe( |
87 | 254 |
catchError(err => this.handleError(err)) |
88 | 255 |
); |
89 | 256 |
} |
90 | 257 |
|
91 |
constructor(protected http: HttpClient) { |
|
92 |
super(http); |
|
258 |
/** |
|
259 |
* Editace dovolené nebo sickday podle jejího id |
|
260 |
* PUT /calendar/edit?[lang=<CZ,EN>] |
|
261 |
* @param calendarEdit calendar to edit |
|
262 |
* @param language specify language |
|
263 |
*/ |
|
264 |
private makePutCalendarEditApiCall(calendarEdit: CalendarEdit, language: Languages) { |
|
265 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
266 |
const options = {params: httpParams}; |
|
267 |
|
|
268 |
return this.http.put<CalendarEdit>(this._userUrl + 'calendar/edit', calendarEdit, options) |
|
269 |
.pipe( |
|
270 |
catchError(err => this.handleError(err)) |
|
271 |
); |
|
93 | 272 |
} |
94 | 273 |
} |
webapp/src/app/services/users.service.spec.ts | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import {UsersService} from './users.service'; |
4 | 4 |
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing'; |
5 |
import {VacationRequest} from '../models/requests.model'; |
|
6 | 5 |
import {RequestStatus, VacationType} from '../enums/common.enum'; |
7 | 6 |
import {environment} from '../../environments/environment'; |
8 | 7 |
|
... | ... | |
40 | 39 |
expect(data[4].timestamp).toBeDefined(); |
41 | 40 |
}); |
42 | 41 |
|
43 |
const req = httpMock.expectOne(baseUrl + '/api/users/requests/authorization?');
|
|
42 |
const req = httpMock.expectOne(baseUrl + '/api/users/requests/authorization'); |
|
44 | 43 |
expect(req.request.method).toBe('GET'); |
45 | 44 |
req.flush(dummyRequests); |
46 | 45 |
}); |
... | ... | |
68 | 67 |
expect(data[1].from).toBeDefined(); |
69 | 68 |
}); |
70 | 69 |
|
71 |
const req = httpMock.expectOne(baseUrl + '/api/users/requests/vacation?');
|
|
70 |
const req = httpMock.expectOne(baseUrl + '/api/users/requests/vacation'); |
|
72 | 71 |
expect(req.request.method).toBe('GET'); |
73 | 72 |
req.flush(dummyRequests); |
74 | 73 |
}); |
... | ... | |
209 | 208 |
expect(data[0].calendar[1].id).toBe(2); |
210 | 209 |
}); |
211 | 210 |
|
212 |
const req = httpMock.expectOne(baseUrl + '/api/users?');
|
|
211 |
const req = httpMock.expectOne(baseUrl + '/api/users'); |
|
213 | 212 |
expect(req.request.method).toBe('GET'); |
214 | 213 |
req.flush(dummyRequests); |
215 | 214 |
}); |
webapp/src/app/services/users.service.ts | ||
---|---|---|
1 | 1 |
import {Injectable} from '@angular/core'; |
2 |
import {HttpClient} from '@angular/common/http'; |
|
2 |
import {HttpClient, HttpParams} from '@angular/common/http';
|
|
3 | 3 |
import {BasicService} from './basic.service'; |
4 | 4 |
import {catchError} from 'rxjs/operators'; |
5 | 5 |
|
... | ... | |
12 | 12 |
providedIn: 'root' |
13 | 13 |
}) |
14 | 14 |
export class UsersService extends BasicService { |
15 |
private _usersUrl = this.baseUrl + '/api/users?';
|
|
16 |
private _statusPrefix = 'status='; |
|
17 |
private _languagePrefix = 'language=';
|
|
18 |
private _vacationRequestsUrl = this.baseUrl + '/api/users/requests/vacation?';
|
|
19 |
private _authorizationRequestsUrl = this.baseUrl + '/api/users/requests/authorization?';
|
|
15 |
private _usersUrl = this.baseUrl + '/api/users'; |
|
16 |
|
|
17 |
constructor(protected http: HttpClient) {
|
|
18 |
super(http);
|
|
19 |
}
|
|
20 | 20 |
|
21 | 21 |
/** |
22 | 22 |
* Returns all authorized users |
23 | 23 |
*/ |
24 | 24 |
getAuthorizedUsers() { |
25 |
return this.makeUsersApiCall(ProfileStatus.AUTHORIZED, '');
|
|
25 |
return this.makeGetUsersApiCall(ProfileStatus.AUTHORIZED, null);
|
|
26 | 26 |
} |
27 | 27 |
|
28 | 28 |
/** |
... | ... | |
31 | 31 |
* @param language filter users based on language |
32 | 32 |
*/ |
33 | 33 |
getAuthorizedUsersWithLanguage(language: Languages) { |
34 |
return this.makeUsersApiCall(ProfileStatus.AUTHORIZED, language); |
|
34 |
return this.makeGetUsersApiCall(ProfileStatus.AUTHORIZED, language);
|
|
35 | 35 |
} |
36 | 36 |
|
37 | 37 |
/** |
38 | 38 |
* Returns all pending users |
39 | 39 |
*/ |
40 | 40 |
getPendingUsers() { |
41 |
return this.makeUsersApiCall(ProfileStatus.PENDING, '');
|
|
41 |
return this.makeGetUsersApiCall(ProfileStatus.PENDING, null);
|
|
42 | 42 |
} |
43 | 43 |
|
44 | 44 |
/** |
... | ... | |
47 | 47 |
* @param language filter users based on language |
48 | 48 |
*/ |
49 | 49 |
getPendingUsersWithLanguage(language: Languages) { |
50 |
return this.makeUsersApiCall(ProfileStatus.PENDING, language); |
|
50 |
return this.makeGetUsersApiCall(ProfileStatus.PENDING, language);
|
|
51 | 51 |
} |
52 | 52 |
|
53 | 53 |
/** |
54 | 54 |
* Return all rejected users |
55 | 55 |
*/ |
56 | 56 |
getRejectedUsers() { |
57 |
return this.makeUsersApiCall(ProfileStatus.REJECTED, '');
|
|
57 |
return this.makeGetUsersApiCall(ProfileStatus.REJECTED, null);
|
|
58 | 58 |
} |
59 | 59 |
|
60 | 60 |
/** |
... | ... | |
63 | 63 |
* @param language filter users based on language |
64 | 64 |
*/ |
65 | 65 |
getRejectedUsersWithLanguage(language: Languages) { |
66 |
return this.makeUsersApiCall(ProfileStatus.REJECTED, language); |
|
66 |
return this.makeGetUsersApiCall(ProfileStatus.REJECTED, language);
|
|
67 | 67 |
} |
68 | 68 |
|
69 | 69 |
/** |
... | ... | |
71 | 71 |
* regardless of language and status |
72 | 72 |
*/ |
73 | 73 |
getUsers() { |
74 |
return this.makeUsersApiCall('', '');
|
|
74 |
return this.makeGetUsersApiCall(null, null);
|
|
75 | 75 |
} |
76 | 76 |
|
77 | 77 |
/** |
78 | 78 |
* Returns all vacation requests |
79 | 79 |
*/ |
80 | 80 |
getVacationRequests() { |
81 |
return this.makeVacationRequestsApiCall('');
|
|
81 |
return this.makeGetVacationRequestsApiCall(null);
|
|
82 | 82 |
} |
83 | 83 |
|
84 | 84 |
/** |
... | ... | |
86 | 86 |
* @param language filter by passed language |
87 | 87 |
*/ |
88 | 88 |
getVacationRequestsWithLanguage(language: Languages) { |
89 |
return this.makeVacationRequestsApiCall(language); |
|
89 |
return this.makeGetVacationRequestsApiCall(language);
|
|
90 | 90 |
} |
91 | 91 |
|
92 | 92 |
|
... | ... | |
94 | 94 |
* Returns all authorization requests |
95 | 95 |
*/ |
96 | 96 |
getAuthorizationRequests() { |
97 |
return this.makeAuthorizationRequestsApiCall('');
|
|
97 |
return this.makeGetAuthorizationRequestsApiCall(null);
|
|
98 | 98 |
} |
99 | 99 |
|
100 | 100 |
|
... | ... | |
103 | 103 |
* @param language filter by passed language |
104 | 104 |
*/ |
105 | 105 |
getAuthorizationRequestsWithLanguage(language: Languages) { |
106 |
return this.makeAuthorizationRequestsApiCall(language); |
|
106 |
return this.makeGetAuthorizationRequestsApiCall(language);
|
|
107 | 107 |
} |
108 | 108 |
|
109 |
private makeAuthorizationRequestsApiCall(language: string) { |
|
110 |
const apiUrl: string = this.createApiUrl(this._authorizationRequestsUrl, '', language); |
|
109 |
/** |
|
110 |
* Získání žádostí o autorizaci všech uživatelů s možností filtrace pomocí úrovně schválení. |
|
111 |
* GET /users/requests/authorization?[lang=<CZ,EN>]&[status=<ACCEPTED, PENDING, REJECTED> |
|
112 |
* @param language filter by language |
|
113 |
*/ |
|
114 |
private makeGetAuthorizationRequestsApiCall(language: string) { |
|
115 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
116 |
const options = {params: httpParams}; |
|
111 | 117 |
|
112 |
return this.http.get<AuthorizationRequest[]>(apiUrl)
|
|
118 |
return this.http.get<AuthorizationRequest[]>(this._usersUrl + '/requests/authorization', options)
|
|
113 | 119 |
.pipe( |
114 | 120 |
catchError(err => this.handleError(err)) |
115 | 121 |
); |
116 | 122 |
} |
117 | 123 |
|
118 |
private makeVacationRequestsApiCall(language: string) { |
|
119 |
const apiUrl: string = this.createApiUrl(this._vacationRequestsUrl, '', language); |
|
124 |
/** |
|
125 |
* Získání žádostí o dovolené a sick days všech uživatelů s možností filtrace pomocí úrovně schválení. |
|
126 |
* GET /users/requests/vacation? [lang=<CZ,EN>]&[status=<ACCEPTED, PENDING, REJECTED>] |
|
127 |
* @param language filter by language |
|
128 |
*/ |
|
129 |
private makeGetVacationRequestsApiCall(language: string) { |
|
130 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
131 |
const options = {params: httpParams}; |
|
120 | 132 |
|
121 |
return this.http.get<VacationRequest[]>(apiUrl)
|
|
133 |
return this.http.get<VacationRequest[]>(this._usersUrl + '/requests/vacation', options)
|
|
122 | 134 |
.pipe( |
123 | 135 |
catchError(err => this.handleError(err)) |
124 | 136 |
); |
125 | 137 |
} |
126 | 138 |
|
127 |
private makeUsersApiCall(status: string, language: string): Observable<UserBasicInformation[]> { |
|
128 |
const apiUrl: string = this.createApiUrl(this._usersUrl, status, language); |
|
139 |
/** |
|
140 |
* Získání všech uživatelů s možností filtrace pomocí statusu |
|
141 |
* GET /users?[lang=<CZ,EN>]&[status=<ACCEPTED, PENDING, REJECTED>] |
|
142 |
* @param status filter by status |
|
143 |
* @param language filter by language |
|
144 |
*/ |
|
145 |
private makeGetUsersApiCall(status: string, language: string): Observable<UserBasicInformation[]> { |
|
146 |
const httpParams: HttpParams = this.createParams({lang: language, status}); |
|
147 |
const options = {params: httpParams}; |
|
129 | 148 |
|
130 |
return this.http.get<UserBasicInformation[]>(apiUrl)
|
|
149 |
return this.http.get<UserBasicInformation[]>(this._usersUrl, options)
|
|
131 | 150 |
.pipe( |
132 | 151 |
catchError(err => this.handleError(err)) |
133 | 152 |
); |
134 | 153 |
} |
135 | 154 |
|
136 |
private createApiUrl(base: string, status: string, language: string): string { |
|
137 |
let apiUrl = base; |
|
138 |
|
|
139 |
if (status.length > 0) { |
|
140 |
apiUrl += this._statusPrefix + status + '&'; |
|
141 |
} |
|
142 |
if (language.length > 0) { |
|
143 |
apiUrl += this._languagePrefix + language; |
|
144 |
} |
|
145 |
|
|
146 |
return apiUrl; |
|
147 |
} |
|
148 |
|
|
149 |
constructor(protected http: HttpClient) { |
|
150 |
super(http); |
|
151 |
} |
|
152 |
|
|
153 | 155 |
} |
Také k dispozici: Unified diff
Re#7493 Finished services except xlsx service