Revize fd5ab42e
Přidáno uživatelem Hung Hoang před téměř 6 roky(ů)
webapp/src/app/dashboard/employer-dashboard/employer-dashboard.component.ts | ||
---|---|---|
1 | 1 |
import {Component, Input, OnInit} from '@angular/core'; |
2 | 2 |
import {MatDialog} from '@angular/material'; |
3 | 3 |
import {AddDaysOffDialogComponent} from '../../add-days-off-dialog/add-days-off-dialog.component'; |
4 |
import {UsersService} from '../../services/users.service'; |
|
4 |
import {UsersService} from '../../services/api/users.service';
|
|
5 | 5 |
import {Requests} from '../../models/requests.model'; |
6 |
import {UserService} from '../../services/user.service'; |
|
7 |
import {ProfileService} from '../../services/profile.service'; |
|
6 |
import {UserService} from '../../services/api/user.service';
|
|
7 |
import {ProfileService} from '../../services/api/profile.service';
|
|
8 | 8 |
import {UserProfile} from '../../models/user.model'; |
9 | 9 |
|
10 | 10 |
@Component({ |
webapp/src/app/employees/employees-list.component.ts | ||
---|---|---|
1 | 1 |
import {Component, OnInit} from '@angular/core'; |
2 |
import {UsersService} from '../services/users.service'; |
|
2 |
import {UsersService} from '../services/api/users.service';
|
|
3 | 3 |
import {Languages, VacationType} from '../enums/common.enum'; |
4 | 4 |
import {MatDialog, MatSnackBar} from '@angular/material'; |
5 | 5 |
import {EditEmployeeDialogComponent} from './edit-employee-dialog/edit-employee-dialog.component'; |
... | ... | |
7 | 7 |
import {UserBasicInformation, UserProfile} from '../models/user.model'; |
8 | 8 |
import {DefaultSettingsDialogComponent} from './default-settings-dialog/default-settings-dialog.component'; |
9 | 9 |
import {Settings} from '../models/settings.model'; |
10 |
import {SettingsService} from '../services/settings.service'; |
|
11 |
import {UserService} from '../services/user.service'; |
|
10 |
import {SettingsService} from '../services/api/settings.service';
|
|
11 |
import {UserService} from '../services/api/user.service';
|
|
12 | 12 |
import {LocalizationService} from '../localization/localization.service'; |
13 |
import {DateFormatterService} from '../shared/date-formatter.service';
|
|
13 |
import {DateFormatterService} from '../services/util/date-formatter.service';
|
|
14 | 14 |
|
15 | 15 |
const daysOfWeek: string[] = [ |
16 | 16 |
'po', |
... | ... | |
78 | 78 |
}) |
79 | 79 |
.afterClosed().subscribe(data => { |
80 | 80 |
if (data && data.isConfirmed) { |
81 |
// TODO API CALL
|
|
82 |
// this.settingsService.postDefaultSettingsWithLanguage(this.toSettings(data), this.localizationService.getCurrentLanguage());
|
|
81 |
this.settingsService.postDefaultSettingsWithLanguage(this.toSettings(data), this.localizationService.getCurrentLanguage())
|
|
82 |
.subscribe((foo: any) => console.log(foo));
|
|
83 | 83 |
} |
84 | 84 |
}); |
85 | 85 |
}); |
webapp/src/app/header/header.component.ts | ||
---|---|---|
1 | 1 |
import { Component, Input } from '@angular/core'; |
2 | 2 |
import { MatDialog } from '@angular/material'; |
3 | 3 |
import { ProfileSettingsComponent } from '../profile-settings/profile-settings.component'; |
4 |
import { ProfileService } from '../services/profile.service'; |
|
4 |
import { ProfileService } from '../services/api/profile.service';
|
|
5 | 5 |
import {LocalizationService} from '../localization/localization.service'; |
6 | 6 |
|
7 | 7 |
@Component({ |
webapp/src/app/menu/menu.component.ts | ||
---|---|---|
1 | 1 |
import { Component, OnInit } from '@angular/core'; |
2 |
import { MenuService } from '../services/menu.service'; |
|
3 | 2 |
import { MenuItem } from './menu-item'; |
4 | 3 |
|
4 |
const MENU_ITEMS: MenuItem[] = [ |
|
5 |
{name: 'Dashboard', routePath: 'dashboard'}, |
|
6 |
{name: 'Zaměstnanci', routePath: 'employees'}, |
|
7 |
]; |
|
8 |
|
|
5 | 9 |
@Component({ |
6 | 10 |
selector: 'app-menu', |
7 | 11 |
templateUrl: './menu.component.html', |
... | ... | |
11 | 15 |
_menuItems: MenuItem[]; |
12 | 16 |
private _selectedMenuItem: MenuItem; |
13 | 17 |
|
18 |
constructor() { |
|
19 |
this._menuItems = MENU_ITEMS; |
|
20 |
} |
|
14 | 21 |
|
15 |
getMenuItems(): void { |
|
16 |
this.menuService.getMenuItems() |
|
17 |
.subscribe(menuItems => this._menuItems = menuItems); |
|
22 |
ngOnInit() { |
|
18 | 23 |
} |
19 | 24 |
|
20 | 25 |
onSelect(menuItem: MenuItem): void { |
21 | 26 |
this._selectedMenuItem = menuItem; |
22 | 27 |
} |
23 |
|
|
24 |
constructor(private menuService: MenuService) { } |
|
25 |
|
|
26 |
ngOnInit() { |
|
27 |
this.getMenuItems(); |
|
28 |
} |
|
29 |
|
|
30 |
|
|
31 | 28 |
} |
webapp/src/app/mock-menu-items.ts | ||
---|---|---|
1 |
import { MenuItem } from './menu/menu-item'; |
|
2 |
|
|
3 |
export const MENU_ITEMS: MenuItem[] = [ |
|
4 |
{name: 'Dashboard', routePath: 'dashboard'}, |
|
5 |
{name: 'Zaměstnanci', routePath: 'employees'}, |
|
6 |
]; |
webapp/src/app/oncoming-days-off/oncoming-days-off.component.ts | ||
---|---|---|
1 | 1 |
import {Component, OnInit} from '@angular/core'; |
2 |
import {UserService} from '../services/user.service'; |
|
2 |
import {UserService} from '../services/api/user.service';
|
|
3 | 3 |
import {VacationType} from '../enums/common.enum'; |
4 | 4 |
|
5 | 5 |
@Component({ |
webapp/src/app/services/api/basic.service.ts | ||
---|---|---|
1 |
import {Injectable} from '@angular/core'; |
|
2 |
import {HttpClient, HttpErrorResponse, HttpParams} from '@angular/common/http'; |
|
3 |
import {throwError} from 'rxjs'; |
|
4 |
import {environment} from '../../../environments/environment'; |
|
5 |
|
|
6 |
@Injectable({ |
|
7 |
providedIn: 'root' |
|
8 |
}) |
|
9 |
export class BasicService { |
|
10 |
protected baseUrl = environment.apiUrl; |
|
11 |
|
|
12 |
constructor(protected http: HttpClient) { } |
|
13 |
|
|
14 |
protected handleError(error: HttpErrorResponse) { |
|
15 |
if (error.error instanceof ErrorEvent) { |
|
16 |
console.error('An error occurred:', error.error.message); |
|
17 |
} else { |
|
18 |
console.error( |
|
19 |
`Backend returned code ${error.status}, ` + |
|
20 |
`body was: ${error.error}`); |
|
21 |
} |
|
22 |
return throwError( |
|
23 |
'Something bad happened; please try again later.'); |
|
24 |
} |
|
25 |
|
|
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 |
} |
|
38 |
} |
webapp/src/app/services/api/profile.service.ts | ||
---|---|---|
1 |
import {Injectable} from '@angular/core'; |
|
2 |
import {UserService} from './user.service'; |
|
3 |
import {Observable} from 'rxjs'; |
|
4 |
import {UserProfile} from '../../models/user.model'; |
|
5 |
|
|
6 |
@Injectable({ |
|
7 |
providedIn: 'root' |
|
8 |
}) |
|
9 |
export class ProfileService { |
|
10 |
private profile: UserProfile; |
|
11 |
|
|
12 |
constructor( |
|
13 |
private userService: UserService |
|
14 |
) { |
|
15 |
// userService.getUserProfile(1) |
|
16 |
// .subscribe((data: UserProfile) => this.profile = data); |
|
17 |
} |
|
18 |
|
|
19 |
getProfile(): Observable<UserProfile> { |
|
20 |
return new Observable((observer) => { |
|
21 |
if (this.profile) { |
|
22 |
observer.next(this.profile); |
|
23 |
observer.complete(); |
|
24 |
} else { |
|
25 |
this.userService.getUserProfile(1) // TODO zmenit id na prihlaseneho uzivatele |
|
26 |
.subscribe((data: UserProfile) => { |
|
27 |
this.profile = data; |
|
28 |
observer.next(this.profile); |
|
29 |
observer.complete(); |
|
30 |
}); |
|
31 |
} |
|
32 |
}); |
|
33 |
} |
|
34 |
|
|
35 |
} |
webapp/src/app/services/api/settings.service.ts | ||
---|---|---|
1 |
import { Injectable } from '@angular/core'; |
|
2 |
import {HttpClient, HttpParams} from '@angular/common/http'; |
|
3 |
import { catchError } from 'rxjs/operators'; |
|
4 |
|
|
5 |
import { BasicService } from './basic.service'; |
|
6 |
import { Settings } from '../../models/settings.model'; |
|
7 |
import {Languages} from '../../enums/common.enum'; |
|
8 |
|
|
9 |
@Injectable({ |
|
10 |
providedIn: 'root' |
|
11 |
}) |
|
12 |
export class SettingsService extends BasicService { |
|
13 |
defaultSettingsUrl = this.baseUrl + '/api/settings'; |
|
14 |
|
|
15 |
constructor(protected http: HttpClient) { |
|
16 |
super(http); |
|
17 |
} |
|
18 |
|
|
19 |
/** |
|
20 |
* Returns default application settings |
|
21 |
* with sickday count and notification |
|
22 |
*/ |
|
23 |
getDefaultSettings() { |
|
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) |
|
46 |
.pipe( |
|
47 |
catchError(err => this.handleError(err)) |
|
48 |
); |
|
49 |
} |
|
50 |
|
|
51 |
postDefaultSettings(settings: Settings) { |
|
52 |
return this.postDefaultSettingsWithOptions(settings, null); |
|
53 |
} |
|
54 |
|
|
55 |
postDefaultSettingsWithLanguage(settings: Settings, language: Languages) { |
|
56 |
return this.postDefaultSettingsWithOptions(settings, language); |
|
57 |
} |
|
58 |
|
|
59 |
private postDefaultSettingsWithOptions(settings: Settings, language: Languages) { |
|
60 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
61 |
const options = {params: httpParams}; |
|
62 |
|
|
63 |
return this.http.post<Settings>(this.defaultSettingsUrl, settings, options) |
|
64 |
.pipe( |
|
65 |
catchError(err => this.handleError(err)) |
|
66 |
); |
|
67 |
} |
|
68 |
} |
webapp/src/app/services/api/user.service.ts | ||
---|---|---|
1 |
import {Injectable} from '@angular/core'; |
|
2 |
import {HttpClient, HttpParams} from '@angular/common/http'; |
|
3 |
|
|
4 |
import {Calendar, CalendarEdit, PostCalendar} from '../../models/calendar.model'; |
|
5 |
import {BasicService} from './basic.service'; |
|
6 |
import {catchError} from 'rxjs/operators'; |
|
7 |
import {Languages, RequestStatus, RequestTypes} from '../../enums/common.enum'; |
|
8 |
import {UserSettings} from '../../models/settings.model'; |
|
9 |
import {UserProfile} from '../../models/user.model'; |
|
10 |
import {UserRequest} from '../../models/requests.model'; |
|
11 |
|
|
12 |
@Injectable({ |
|
13 |
providedIn: 'root' |
|
14 |
}) |
|
15 |
export class UserService extends BasicService { // dost podobny k usersService, mozna zmenit v rest api |
|
16 |
private _userUrl = this.baseUrl + '/api/user/'; |
|
17 |
|
|
18 |
constructor(protected http: HttpClient) { |
|
19 |
super(http); |
|
20 |
} |
|
21 |
|
|
22 |
/** |
|
23 |
* Returns user 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 |
getUserProfile(id: number) { |
|
29 |
return this.makeGetProfileApiCall(id.toString(), null); |
|
30 |
} |
|
31 |
|
|
32 |
/** |
|
33 |
* Overloaded version of getUserProfile to filter profiles |
|
34 |
* by language |
|
35 |
* UserProfile.notification might be returned as string instead of date |
|
36 |
* @param id user profile id |
|
37 |
* @param language language to filtery by |
|
38 |
*/ |
|
39 |
getUserProfileWithLanguage(id: number, language: Languages) { |
|
40 |
return this.makeGetProfileApiCall(id.toString(), language); |
|
41 |
} |
|
42 |
|
|
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); |
|
49 |
} |
|
50 |
|
|
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); |
|
58 |
} |
|
59 |
|
|
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); |
|
67 |
} |
|
68 |
|
|
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); |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* Put user settings with given id for the user |
|
100 |
* @param settings settings to be put |
|
101 |
*/ |
|
102 |
putUserSettings(settings: UserSettings) { |
|
103 |
return this.makePutUserSettingsApiCall(settings, null); |
|
104 |
} |
|
105 |
|
|
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: UserSettings, language: Languages) { |
|
112 |
return this.makePutUserSettingsApiCall(settings, language); |
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* Accept or deny user request |
|
117 |
* @param request request to accept or deny |
|
118 |
* @param type request type |
|
119 |
*/ |
|
120 |
putUserRequest(request: UserRequest, type: RequestTypes) { |
|
121 |
return this.makePutUserRequestApiCall(request, type, null); |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* Accept or deny user request |
|
126 |
* @param request request to accept or deny |
|
127 |
* @param type reqeust type |
|
128 |
* @param language specify language |
|
129 |
*/ |
|
130 |
putUserRequestWithLanguage(request: UserRequest, type: RequestTypes, language: Languages) { |
|
131 |
return this.makePutUserRequestApiCall(request, type, language); |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* Edit calendar |
|
136 |
* @param calendarEdit calendar day to be edited |
|
137 |
* @param language specify language |
|
138 |
*/ |
|
139 |
putCalendarEdit(calendarEdit: CalendarEdit, language: Languages) { |
|
140 |
return this.makePutCalendarEditApiCall(calendarEdit, null); |
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 |
* Delete calendar vacation day with given id |
|
145 |
* @param id calendar day id to be deleted |
|
146 |
* @param language specify language |
|
147 |
*/ |
|
148 |
deleteCalendar(id: number, language: Languages) { |
|
149 |
return this.makeDeleteCalendarApiCall(id, language); |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Získání profilu aktuálně přihlášeného uživatele nebo uživatele podle zadaného id. |
|
154 |
* GET /user/<{id} || me>/profile?[lang=<CZ,EN>] |
|
155 |
* @param id id of profile to get (number or 'me') |
|
156 |
* @param language filter by language |
|
157 |
*/ |
|
158 |
private makeGetProfileApiCall(id: string, language: string) { |
|
159 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
160 |
const options = {params: httpParams}; |
|
161 |
|
|
162 |
return this.http.get<UserProfile>(this._userUrl + id + '/profile', options) |
|
163 |
.pipe( |
|
164 |
catchError(err => this.handleError(err)) |
|
165 |
); |
|
166 |
} |
|
167 |
|
|
168 |
/** |
|
169 |
* 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í. |
|
170 |
* GET /user/<{id} || me>/calendar?[lang=<CZ,EN>]&from=yyyy/mm/dd, [to=yyyy/mm/dd], [status=<ACCEPTED, PENDING, REJECTED>] |
|
171 |
* @param id id of calendar to get (number or 'me') |
|
172 |
* @param from mandatory param |
|
173 |
* @param to upper limit of days |
|
174 |
* @param language filter by language |
|
175 |
* @param status filter by status |
|
176 |
*/ |
|
177 |
private makeGetCalendarApiCall(id: string, from: Date, to: Date, language: Languages, status: RequestStatus) { |
|
178 |
const fromString: string = from.getFullYear() + '/' + from.getMonth() + '/' + from.getDate(); |
|
179 |
let toString: string; |
|
180 |
if (to != null) { |
|
181 |
toString = to.getFullYear() + '/' + to.getMonth() + '/' + to.getDate(); |
|
182 |
} |
|
183 |
|
|
184 |
const httpParams: HttpParams = this.createParams({lang: language, from: fromString, to: toString, status}); |
|
185 |
const options = {params: httpParams}; |
|
186 |
|
|
187 |
return this.http.get<Calendar[]>(this._userUrl + id + '/calendar', options) |
|
188 |
.pipe( |
|
189 |
catchError(err => this.handleError(err)) |
|
190 |
); |
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* Povolení nebo zamítnutí žádosti nebo “smazání“ uživatele (změna statusu na REJECTED) |
|
195 |
* PUT /user/requests?[lang=<CZ,EN>]&type=<VACATION, AUTHORIZATION> |
|
196 |
* @param request request to accept or reject |
|
197 |
* @param reqType request type |
|
198 |
* @param language specify language |
|
199 |
*/ |
|
200 |
private makePutUserRequestApiCall(request: UserRequest, reqType: RequestTypes, language: Languages) { |
|
201 |
const httpParams: HttpParams = this.createParams({type: reqType, lang: language}); |
|
202 |
const options = {params: httpParams}; |
|
203 |
|
|
204 |
return this.http.put<UserRequest>(this._userUrl + 'requests', request, options) |
|
205 |
.pipe( |
|
206 |
catchError(err => this.handleError(err)) |
|
207 |
); |
|
208 |
} |
|
209 |
|
|
210 |
|
|
211 |
/** |
|
212 |
* Změna nastavení uživatele podle id |
|
213 |
* PUT /user/settings?[lang=<CZ,EN>] |
|
214 |
* @param settings setting to be set for given user |
|
215 |
* @param language specified language |
|
216 |
*/ |
|
217 |
private makePutUserSettingsApiCall(settings: UserSettings, language: Languages) { |
|
218 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
219 |
const options = {params: httpParams}; |
|
220 |
|
|
221 |
return this.http.put<UserSettings>(this._userUrl + 'settings', settings, options) |
|
222 |
.pipe( |
|
223 |
catchError(err => this.handleError(err)) |
|
224 |
); |
|
225 |
} |
|
226 |
|
|
227 |
/** |
|
228 |
* Vytvoření nové dovolené nebo sick day |
|
229 |
* POST /user/calendar/create?[lang=<CZ,EN>] |
|
230 |
* @param calendar calendar to be posted |
|
231 |
* @param language specified language |
|
232 |
*/ |
|
233 |
private makePostCalendarApiCall(calendar: PostCalendar, language: Languages) { |
|
234 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
235 |
const options = {params: httpParams}; |
|
236 |
|
|
237 |
return this.http.post<PostCalendar>(this._userUrl + 'calendar/create', calendar, options) |
|
238 |
.pipe( |
|
239 |
catchError(err => this.handleError(err)) |
|
240 |
); |
|
241 |
|
|
242 |
} |
|
243 |
|
|
244 |
/** |
|
245 |
* Smazání dovolené nebo sickday podle jejího id |
|
246 |
* DELETE /calendar/delete?[lang=<CZ,EN>] |
|
247 |
* @param id id of calendar to delete |
|
248 |
* @param language specify language |
|
249 |
*/ |
|
250 |
private makeDeleteCalendarApiCall(id: number, language: Languages) { |
|
251 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
252 |
const options = {params: httpParams}; |
|
253 |
|
|
254 |
return this.http.delete(this._userUrl + 'calendar/' + id + '/delete', options) |
|
255 |
.pipe( |
|
256 |
catchError(err => this.handleError(err)) |
|
257 |
); |
|
258 |
} |
|
259 |
|
|
260 |
/** |
|
261 |
* Editace dovolené nebo sickday podle jejího id |
|
262 |
* PUT /calendar/edit?[lang=<CZ,EN>] |
|
263 |
* @param calendarEdit calendar to edit |
|
264 |
* @param language specify language |
|
265 |
*/ |
|
266 |
private makePutCalendarEditApiCall(calendarEdit: CalendarEdit, language: Languages) { |
|
267 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
268 |
const options = {params: httpParams}; |
|
269 |
|
|
270 |
return this.http.put<CalendarEdit>(this._userUrl + 'calendar/edit', calendarEdit, options) |
|
271 |
.pipe( |
|
272 |
catchError(err => this.handleError(err)) |
|
273 |
); |
|
274 |
} |
|
275 |
} |
webapp/src/app/services/api/users.service.ts | ||
---|---|---|
1 |
import {Injectable} from '@angular/core'; |
|
2 |
import {HttpClient, HttpParams} from '@angular/common/http'; |
|
3 |
import {BasicService} from './basic.service'; |
|
4 |
import {catchError} from 'rxjs/operators'; |
|
5 |
|
|
6 |
import {AuthorizationRequest, VacationRequest} from '../../models/requests.model'; |
|
7 |
import {Languages, ProfileStatus} from '../../enums/common.enum'; |
|
8 |
import {Observable} from 'rxjs'; |
|
9 |
import {UserBasicInformation} from '../../models/user.model'; |
|
10 |
|
|
11 |
@Injectable({ |
|
12 |
providedIn: 'root' |
|
13 |
}) |
|
14 |
export class UsersService extends BasicService { |
|
15 |
private _usersUrl = this.baseUrl + '/api/users'; |
|
16 |
|
|
17 |
constructor(protected http: HttpClient) { |
|
18 |
super(http); |
|
19 |
} |
|
20 |
|
|
21 |
/** |
|
22 |
* Returns all authorized users |
|
23 |
*/ |
|
24 |
getAuthorizedUsers() { |
|
25 |
return this.makeGetUsersApiCall(ProfileStatus.AUTHORIZED, null); |
|
26 |
} |
|
27 |
|
|
28 |
/** |
|
29 |
* Returns all authorized users with specified language |
|
30 |
* overloaded version of getAuthorizedUsers |
|
31 |
* @param language filter users based on language |
|
32 |
*/ |
|
33 |
getAuthorizedUsersWithLanguage(language: Languages) { |
|
34 |
return this.makeGetUsersApiCall(ProfileStatus.AUTHORIZED, language); |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
38 |
* Returns all pending users |
|
39 |
*/ |
|
40 |
getPendingUsers() { |
|
41 |
return this.makeGetUsersApiCall(ProfileStatus.PENDING, null); |
|
42 |
} |
|
43 |
|
|
44 |
/** |
|
45 |
* Returns all pending users with specified language |
|
46 |
* overloaded version of getPendingUsers |
|
47 |
* @param language filter users based on language |
|
48 |
*/ |
|
49 |
getPendingUsersWithLanguage(language: Languages) { |
|
50 |
return this.makeGetUsersApiCall(ProfileStatus.PENDING, language); |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* Return all rejected users |
|
55 |
*/ |
|
56 |
getRejectedUsers() { |
|
57 |
return this.makeGetUsersApiCall(ProfileStatus.REJECTED, null); |
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* Returns all rejected users with specified language |
|
62 |
* overloaded version of getRejectedUsers |
|
63 |
* @param language filter users based on language |
|
64 |
*/ |
|
65 |
getRejectedUsersWithLanguage(language: Languages) { |
|
66 |
return this.makeGetUsersApiCall(ProfileStatus.REJECTED, language); |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* Default api call which returns all users in the database |
|
71 |
* regardless of language and status |
|
72 |
*/ |
|
73 |
getUsers() { |
|
74 |
return this.makeGetUsersApiCall(null, null); |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* Returns all vacation requests |
|
79 |
*/ |
|
80 |
getVacationRequests() { |
|
81 |
return this.makeGetVacationRequestsApiCall(null); |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* Returns vacations filtered by language |
|
86 |
* @param language filter by passed language |
|
87 |
*/ |
|
88 |
getVacationRequestsWithLanguage(language: Languages) { |
|
89 |
return this.makeGetVacationRequestsApiCall(language); |
|
90 |
} |
|
91 |
|
|
92 |
|
|
93 |
/** |
|
94 |
* Returns all authorization requests |
|
95 |
*/ |
|
96 |
getAuthorizationRequests() { |
|
97 |
return this.makeGetAuthorizationRequestsApiCall(null); |
|
98 |
} |
|
99 |
|
|
100 |
|
|
101 |
/** |
|
102 |
* Returns authorization requests filtered by language |
|
103 |
* @param language filter by passed language |
|
104 |
*/ |
|
105 |
getAuthorizationRequestsWithLanguage(language: Languages) { |
|
106 |
return this.makeGetAuthorizationRequestsApiCall(language); |
|
107 |
} |
|
108 |
|
|
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}; |
|
117 |
|
|
118 |
return this.http.get<AuthorizationRequest[]>(this._usersUrl + '/requests/authorization', options) |
|
119 |
.pipe( |
|
120 |
catchError(err => this.handleError(err)) |
|
121 |
); |
|
122 |
} |
|
123 |
|
|
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}; |
|
132 |
|
|
133 |
return this.http.get<VacationRequest[]>(this._usersUrl + '/requests/vacation', options) |
|
134 |
.pipe( |
|
135 |
catchError(err => this.handleError(err)) |
|
136 |
); |
|
137 |
} |
|
138 |
|
|
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}; |
|
148 |
|
|
149 |
return this.http.get<UserBasicInformation[]>(this._usersUrl, options) |
|
150 |
.pipe( |
|
151 |
catchError(err => this.handleError(err)) |
|
152 |
); |
|
153 |
} |
|
154 |
|
|
155 |
} |
webapp/src/app/services/basic.service.ts | ||
---|---|---|
1 |
import {Injectable} from '@angular/core'; |
|
2 |
import {HttpClient, HttpErrorResponse, HttpParams} from '@angular/common/http'; |
|
3 |
import {throwError} from 'rxjs'; |
|
4 |
import {environment} from '../../environments/environment'; |
|
5 |
|
|
6 |
@Injectable({ |
|
7 |
providedIn: 'root' |
|
8 |
}) |
|
9 |
export class BasicService { |
|
10 |
protected baseUrl = environment.apiUrl; |
|
11 |
|
|
12 |
constructor(protected http: HttpClient) { } |
|
13 |
|
|
14 |
protected handleError(error: HttpErrorResponse) { |
|
15 |
if (error.error instanceof ErrorEvent) { |
|
16 |
console.error('An error occurred:', error.error.message); |
|
17 |
} else { |
|
18 |
console.error( |
|
19 |
`Backend returned code ${error.status}, ` + |
|
20 |
`body was: ${error.error}`); |
|
21 |
} |
|
22 |
return throwError( |
|
23 |
'Something bad happened; please try again later.'); |
|
24 |
} |
|
25 |
|
|
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 |
} |
|
38 |
} |
webapp/src/app/services/menu.service.ts | ||
---|---|---|
1 |
import { Injectable } from '@angular/core'; |
|
2 |
import { MenuItem } from '../menu/menu-item'; |
|
3 |
import { Observable, of } from 'rxjs'; |
|
4 |
import { MENU_ITEMS } from '../mock-menu-items'; |
|
5 |
|
|
6 |
@Injectable({ |
|
7 |
providedIn: 'root' |
|
8 |
}) |
|
9 |
export class MenuService { |
|
10 |
|
|
11 |
getMenuItems(): Observable<MenuItem[]> { |
|
12 |
return of(MENU_ITEMS); |
|
13 |
} |
|
14 |
|
|
15 |
constructor() { } |
|
16 |
} |
webapp/src/app/services/profile.service.ts | ||
---|---|---|
1 |
import {Injectable} from '@angular/core'; |
|
2 |
import {UserService} from './user.service'; |
|
3 |
import {Observable} from 'rxjs'; |
|
4 |
import {UserProfile} from '../models/user.model'; |
|
5 |
|
|
6 |
@Injectable({ |
|
7 |
providedIn: 'root' |
|
8 |
}) |
|
9 |
export class ProfileService { |
|
10 |
private profile: UserProfile; |
|
11 |
|
|
12 |
constructor( |
|
13 |
private userService: UserService |
|
14 |
) { |
|
15 |
// userService.getUserProfile(1) |
|
16 |
// .subscribe((data: UserProfile) => this.profile = data); |
|
17 |
} |
|
18 |
|
|
19 |
getProfile(): Observable<UserProfile> { |
|
20 |
return new Observable((observer) => { |
|
21 |
if (this.profile) { |
|
22 |
observer.next(this.profile); |
|
23 |
observer.complete(); |
|
24 |
} else { |
|
25 |
this.userService.getUserProfile(1) // TODO zmenit id na prihlaseneho uzivatele |
|
26 |
.subscribe((data: UserProfile) => { |
|
27 |
this.profile = data; |
|
28 |
observer.next(this.profile); |
|
29 |
observer.complete(); |
|
30 |
}); |
|
31 |
} |
|
32 |
}); |
|
33 |
} |
|
34 |
|
|
35 |
} |
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 |
import { Injectable } from '@angular/core'; |
|
2 |
import {HttpClient, HttpParams} from '@angular/common/http'; |
|
3 |
import { catchError } from 'rxjs/operators'; |
|
4 |
|
|
5 |
import { BasicService } from './basic.service'; |
|
6 |
import { Settings } from '../models/settings.model'; |
|
7 |
import {Languages} from '../enums/common.enum'; |
|
8 |
|
|
9 |
@Injectable({ |
|
10 |
providedIn: 'root' |
|
11 |
}) |
|
12 |
export class SettingsService extends BasicService { |
|
13 |
defaultSettingsUrl = this.baseUrl + '/api/settings'; |
|
14 |
|
|
15 |
constructor(protected http: HttpClient) { |
|
16 |
super(http); |
|
17 |
} |
|
18 |
|
|
19 |
/** |
|
20 |
* Returns default application settings |
|
21 |
* with sickday count and notification |
|
22 |
*/ |
|
23 |
getDefaultSettings() { |
|
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) |
|
46 |
.pipe( |
|
47 |
catchError(err => this.handleError(err)) |
|
48 |
); |
|
49 |
} |
|
50 |
|
|
51 |
postDefaultSettings(settings: Settings) { |
|
52 |
return this.postDefaultSettingsWithOptions(settings, null); |
|
53 |
} |
|
54 |
|
|
55 |
postDefaultSettingsWithLanguage(settings: Settings, language: Languages) { |
|
56 |
return this.postDefaultSettingsWithOptions(settings, language); |
|
57 |
} |
|
58 |
|
|
59 |
private postDefaultSettingsWithOptions(settings: Settings, language: Languages) { |
|
60 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
61 |
const options = {params: httpParams}; |
|
62 |
|
|
63 |
return this.http.post<Settings>(this.defaultSettingsUrl, settings, options) |
|
64 |
.pipe( |
|
65 |
catchError(err => this.handleError(err)) |
|
66 |
); |
|
67 |
} |
|
68 |
} |
webapp/src/app/services/tests/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 '../api/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/tests/user.service.spec.ts | ||
---|---|---|
1 |
import {TestBed} from '@angular/core/testing'; |
|
2 |
|
|
3 |
import {UserService} from '../api/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/tests/users.service.spec.ts | ||
---|---|---|
1 |
import {TestBed} from '@angular/core/testing'; |
|
2 |
|
|
3 |
import {UsersService} from '../api/users.service'; |
|
4 |
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing'; |
|
5 |
import {RequestStatus, VacationType} from '../../enums/common.enum'; |
|
6 |
import {environment} from '../../../environments/environment'; |
|
7 |
|
|
8 |
describe('UsersService', () => { |
|
9 |
let service: UsersService; |
|
10 |
let httpMock: HttpTestingController; |
|
11 |
const baseUrl: string = environment.apiUrl; |
|
12 |
|
|
13 |
beforeEach(() => { |
|
14 |
TestBed.configureTestingModule({ |
|
15 |
imports: [HttpClientTestingModule], |
|
16 |
providers: [UsersService] |
|
17 |
}); |
|
18 |
|
|
19 |
service = TestBed.get(UsersService); |
|
20 |
httpMock = TestBed.get(HttpTestingController); |
|
21 |
}); |
|
22 |
afterEach(() => httpMock.verify()); |
|
23 |
|
|
24 |
|
|
25 |
it('getAuthorizationRequests', () => { |
|
26 |
const dummyRequests = [ |
|
27 |
{ id: 1, firstName: 'Tomas', lastName: 'Novak', timestamp: '2019/05/24 21:55:11' }, |
|
28 |
{ id: 2, firstName: 'Tomas', lastName: 'Novak', timestamp: '2019/05/24 21:55:11' }, |
|
29 |
{ id: 3, firstName: 'Tomas', lastName: 'Novak', timestamp: '2019/05/24 21:55:11' }, |
|
30 |
{ id: 4, firstName: 'Tomas', lastName: 'Novak', timestamp: '2019/05/24 21:55:11' }, |
|
31 |
{ id: 5, firstName: 'Tomas', lastName: 'Novak', timestamp: '2019/05/24 21:55:11' } |
|
32 |
]; |
|
33 |
|
|
34 |
service.getAuthorizationRequests().subscribe((data: any) => { |
|
35 |
expect(data.length).toBe(5); |
|
36 |
expect(data[4].lastName).toBe('Novak'); |
|
37 |
expect(data[4].firstName).toBe('Tomas'); |
|
38 |
expect(data[4].id).toBe(5); |
|
39 |
expect(data[4].timestamp).toBeDefined(); |
|
40 |
}); |
|
41 |
|
|
42 |
const req = httpMock.expectOne(baseUrl + '/api/users/requests/authorization'); |
|
43 |
expect(req.request.method).toBe('GET'); |
|
44 |
req.flush(dummyRequests); |
|
45 |
}); |
|
46 |
|
|
47 |
it('getVacationRequests', () => { |
|
48 |
const dummyRequests = [ |
|
49 |
{id: 1, firstName: 'Tomas', lastName: 'Novak', date: '2019/05/24', type: 'SICKDAY', timestamp: '2019/05/24 21:59:32'}, |
|
50 |
{ id: 2, firstName: 'Tomas', lastName: 'Novak', date: '2019/05/24', from: '09:30', to: '18:30', type: 'VACATION', timestamp: '2019/05/24 21:59:32' }, |
|
51 |
{id: 3, firstName: 'Tomas', lastName: 'Novak', date: '2019/05/24', type: 'SICKDAY', timestamp: '2019/05/24 21:59:32'}, |
|
52 |
{ id: 4, firstName: 'Tomas', lastName: 'Novak', date: '2019/05/24', from: '09:30', to: '18:30', type: 'VACATION', timestamp: '2019/05/24 21:59:32' }, |
|
53 |
{id: 5, firstName: 'Tomas', lastName: 'Novak', date: '2019/05/24', type: 'SICKDAY', timestamp: '2019/05/24 21:59:32'} |
|
54 |
]; |
|
55 |
service.getVacationRequests().subscribe((data: any) => { |
|
56 |
expect(data.length).toBe(5); |
|
57 |
|
|
58 |
expect(data[0].firstName).toBeDefined(); |
|
59 |
expect(data[0].lastName).toBeDefined(); |
|
60 |
|
|
61 |
expect(data[0].type).toBe(VacationType.SICKDAY); |
|
62 |
expect(data[0].to).toBeUndefined(); |
|
63 |
expect(data[0].from).toBeUndefined(); |
|
64 |
|
|
65 |
expect(data[1].type).toBe(VacationType.VACATION); |
|
66 |
expect(data[1].to).toBeDefined(); |
|
67 |
expect(data[1].from).toBeDefined(); |
|
68 |
}); |
|
69 |
|
|
70 |
const req = httpMock.expectOne(baseUrl + '/api/users/requests/vacation'); |
|
71 |
expect(req.request.method).toBe('GET'); |
|
72 |
req.flush(dummyRequests); |
|
73 |
}); |
|
74 |
|
|
75 |
|
|
76 |
it('getAllUsers', () => { |
|
77 |
const dummyRequests = [ |
|
78 |
{ |
|
79 |
id: 1, |
|
80 |
firstName: 'Tomas', |
|
81 |
lastName: 'unknown', |
|
82 |
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg', |
|
83 |
calendar: [ |
|
84 |
{ |
|
85 |
id: 1, |
|
86 |
date: '2019/05/24', |
|
87 |
from: '09:00', |
|
88 |
to: '13:00', |
|
89 |
type: 'VACATION', |
|
90 |
status: 'ACCEPTED' |
|
91 |
}, |
|
92 |
{ |
|
93 |
id: 2, |
|
94 |
date: '2019/05/25', |
|
95 |
from: '09:00', |
|
96 |
to: '13:00', |
|
97 |
type: 'VACATION', |
|
98 |
status: 'ACCEPTED' |
|
99 |
} |
|
100 |
] |
|
101 |
}, |
|
102 |
{ |
|
103 |
id: 2, |
|
104 |
firstName: 'Tomas', |
|
105 |
lastName: 'unknown', |
|
106 |
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg', |
|
107 |
calendar: [ |
|
108 |
{ |
|
109 |
id: 1, |
|
110 |
date: '2019/05/24', |
|
111 |
from: '09:00', |
|
112 |
to: '13:00', |
|
113 |
type: 'VACATION', |
|
114 |
status: 'ACCEPTED' |
|
115 |
}, |
|
116 |
{ |
|
117 |
id: 2, |
|
118 |
date: '2019/05/25', |
|
119 |
from: '09:00', |
|
120 |
to: '13:00', |
|
121 |
type: 'VACATION', |
|
122 |
status: 'ACCEPTED' |
|
123 |
} |
|
124 |
] |
|
125 |
}, |
|
126 |
{ |
|
127 |
id: 3, |
|
128 |
firstName: 'Tomas', |
|
129 |
lastName: 'unknown', |
|
130 |
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg', |
|
131 |
calendar: [ |
|
132 |
{ |
|
133 |
id: 1, |
|
134 |
date: '2019/05/24', |
|
135 |
from: '09:00', |
|
136 |
to: '13:00', |
|
137 |
type: 'VACATION', |
|
138 |
status: 'ACCEPTED' |
|
139 |
}, |
|
140 |
{ |
|
141 |
id: 2, |
|
142 |
date: '2019/05/25', |
|
143 |
from: '09:00', |
|
144 |
to: '13:00', |
|
145 |
type: 'VACATION', |
|
146 |
status: 'ACCEPTED' |
|
147 |
} |
|
148 |
] |
|
149 |
}, |
|
150 |
{ |
|
151 |
id: 4, |
|
152 |
firstName: 'Tomas', |
|
153 |
lastName: 'unknown', |
|
154 |
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg', |
|
155 |
calendar: [ |
|
156 |
{ |
|
157 |
id: 1, |
|
158 |
date: '2019/05/24', |
|
159 |
from: '09:00', |
|
160 |
to: '13:00', |
|
161 |
type: 'VACATION', |
|
162 |
status: 'ACCEPTED' |
|
163 |
}, |
|
164 |
{ |
|
165 |
id: 2, |
|
166 |
date: '2019/05/25', |
|
167 |
from: '09:00', |
|
168 |
to: '13:00', |
|
169 |
type: 'VACATION', |
|
170 |
status: 'ACCEPTED' |
|
171 |
} |
|
172 |
] |
|
173 |
}, |
|
174 |
{ |
|
175 |
id: 5, |
|
176 |
firstName: 'Tomas', |
|
177 |
lastName: 'unknown', |
|
178 |
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg', |
|
179 |
calendar: [ |
|
180 |
{ |
|
181 |
id: 1, |
|
182 |
date: '2019/05/24', |
|
183 |
from: '09:00', |
|
184 |
to: '13:00', |
|
185 |
type: 'VACATION', |
|
186 |
status: 'ACCEPTED' |
|
187 |
}, |
|
188 |
{ |
|
189 |
id: 2, |
|
190 |
date: '2019/05/25', |
|
191 |
from: '09:00', |
|
192 |
to: '13:00', |
|
193 |
type: 'VACATION', |
|
194 |
status: 'ACCEPTED' |
|
195 |
} |
|
196 |
] |
|
197 |
} |
|
198 |
]; |
|
199 |
service.getUsers().subscribe((data: any) => { |
|
200 |
expect(data.length).toBe(5); |
|
201 |
expect(data[0].id).toBe(1); |
|
202 |
expect(data[0].firstName).toBeDefined(); |
|
203 |
expect(data[0].lastName).toBeDefined(); |
|
204 |
expect(data[0].photo).toBeDefined(); |
|
205 |
expect(data[0].calendar[0].type).toBe(VacationType.VACATION); |
|
206 |
expect(data[0].calendar[0].status).toBe(RequestStatus.ACCEPTED); |
|
207 |
expect(data[0].calendar[0].id).toBe(1); |
|
208 |
expect(data[0].calendar[1].id).toBe(2); |
|
209 |
}); |
|
210 |
|
|
211 |
const req = httpMock.expectOne(baseUrl + '/api/users'); |
|
212 |
expect(req.request.method).toBe('GET'); |
|
213 |
req.flush(dummyRequests); |
|
214 |
}); |
|
215 |
|
|
216 |
}); |
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 |
|
Také k dispozici: Unified diff
Refactor service structure