Revize d2799ca5
Přidáno uživatelem Jakub Danek před více než 5 roky(ů)
webapp/src/app/dashboard/dashboard.component.ts | ||
---|---|---|
36 | 36 |
ngOnInit() { |
37 | 37 |
this.selectedMonth = this.dateToolsService.toStartOfMonth(new Date()); |
38 | 38 |
|
39 |
this.userService.getLoggedUserProfile() |
|
39 |
this.usersService.getLoggedUserProfile()
|
|
40 | 40 |
.subscribe((data: UserProfile) => { |
41 | 41 |
this.profile = data; |
42 | 42 |
if (this.isEmployer()) { |
... | ... | |
117 | 117 |
} |
118 | 118 |
|
119 | 119 |
private loadProfile() { |
120 |
this.userService.getLoggedUserProfile() |
|
120 |
this.usersService.getLoggedUserProfile()
|
|
121 | 121 |
.subscribe((data: UserProfile) => this.profile = data); |
122 | 122 |
} |
123 | 123 |
|
webapp/src/app/employees/employees-list.component.ts | ||
---|---|---|
106 | 106 |
* @param user user information |
107 | 107 |
*/ |
108 | 108 |
openEditUserDialog(user: User): void { |
109 |
this.userService.getUserProfile(user.id) |
|
109 |
this.usersService.getUserProfile(user.id)
|
|
110 | 110 |
.subscribe((userProfile: UserProfile) => { |
111 | 111 |
const dialogRef = this.dialog.open(EditEmployeeDialogComponent, { |
112 | 112 |
data: userProfile, |
webapp/src/app/employees/user-profile/user-profile-dialog.component.ts | ||
---|---|---|
6 | 6 |
import {UserService} from '../../services/api/user.service'; |
7 | 7 |
import {DateToolsService} from '../../services/util/date-tools.service'; |
8 | 8 |
import {LocalizationService} from '../../localization/localization.service'; |
9 |
import {UsersService} from "../../services/api/users.service"; |
|
9 | 10 |
|
10 | 11 |
@Component({ |
11 | 12 |
selector: 'app-user-profile', |
... | ... | |
21 | 22 |
public dialogRef: MatDialogRef<UserProfileDialogComponent>, |
22 | 23 |
@Inject(MAT_DIALOG_DATA) public data: UserProfileDialogData, |
23 | 24 |
private userService: UserService, |
25 |
private usersService: UsersService, |
|
24 | 26 |
private dateToolsService: DateToolsService, |
25 | 27 |
private localizationService: LocalizationService |
26 | 28 |
) { } |
... | ... | |
44 | 46 |
} |
45 | 47 |
|
46 | 48 |
private loadProfile() { |
47 |
this.userService.getUserProfile(this.data.userId) |
|
49 |
this.usersService.getUserProfile(this.data.userId)
|
|
48 | 50 |
.subscribe((data: UserProfile) => this.profile = data); |
49 | 51 |
} |
50 | 52 |
|
webapp/src/app/header/header.component.ts | ||
---|---|---|
4 | 4 |
import {UserService} from '../services/api/user.service'; |
5 | 5 |
import {UserProfile} from '../models/user.model'; |
6 | 6 |
import {ProfileSettingsComponent} from '../profile-settings/profile-settings.component'; |
7 |
import {UsersService} from "../services/api/users.service"; |
|
7 | 8 |
|
8 | 9 |
@Component({ |
9 | 10 |
selector: 'app-header', |
... | ... | |
17 | 18 |
constructor( |
18 | 19 |
private dialog: MatDialog, |
19 | 20 |
private localizationService: LocalizationService, |
20 |
private userService: UserService |
|
21 |
private userService: UserService, |
|
22 |
private usersService: UsersService |
|
21 | 23 |
) { |
22 |
userService.getLoggedUserProfile() |
|
24 |
usersService.getLoggedUserProfile()
|
|
23 | 25 |
.subscribe((data: UserProfile) => this.profile = data); |
24 | 26 |
this.language = this.localizationService.getCurrentLanguage(); |
25 | 27 |
} |
... | ... | |
28 | 30 |
this.language = this.localizationService.switchLocale(language); |
29 | 31 |
} |
30 | 32 |
onProfileClick(): void { |
31 |
this.userService.getLoggedUserProfile() |
|
33 |
this.usersService.getLoggedUserProfile()
|
|
32 | 34 |
.subscribe((data: UserProfile) => { |
33 | 35 |
this.profile = data; |
34 | 36 |
|
... | ... | |
47 | 49 |
}, |
48 | 50 |
this.localizationService.getCurrentLanguage() |
49 | 51 |
).subscribe(() => { |
50 |
this.userService.getLoggedUserProfile().subscribe((profile: UserProfile) => this.profile = profile); |
|
52 |
this.usersService.getLoggedUserProfile().subscribe((profile: UserProfile) => this.profile = profile);
|
|
51 | 53 |
}); |
52 | 54 |
}); |
53 | 55 |
}); |
webapp/src/app/services/api/user.service.ts | ||
---|---|---|
6 | 6 |
import {catchError} from 'rxjs/operators'; |
7 | 7 |
import {Languages, RequestStatus, RequestTypes} from '../../enums/common.enum'; |
8 | 8 |
import {NotificationSettings, UserSettings} from '../../models/settings.model'; |
9 |
import {UserProfile} from '../../models/user.model'; |
|
10 | 9 |
import {UserRequest} from '../../models/requests.model'; |
11 | 10 |
import {MatSnackBar} from '@angular/material'; |
12 | 11 |
import {DateFormatterService} from '../util/date-formatter.service'; |
... | ... | |
16 | 15 |
providedIn: 'root' |
17 | 16 |
}) |
18 | 17 |
export class UserService extends BasicService { // dost podobny k usersService, mozna zmenit v rest api |
19 |
private _userUrl = this.baseUrl + '/api/user/'; |
|
18 |
private _userUrl = this.baseUrl + '/api/users/';
|
|
20 | 19 |
|
21 | 20 |
constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService, private dateFormater: DateFormatterService) { |
22 | 21 |
super(http, snackBar, translateService); |
23 | 22 |
} |
24 | 23 |
|
25 |
/** |
|
26 |
* Returns user profile if the user making this call |
|
27 |
* is logged as admin |
|
28 |
* UserProfile.notification might be returned as string instead of date |
|
29 |
* @param id user profile id |
|
30 |
*/ |
|
31 |
getUserProfile(id: number) { |
|
32 |
return this.makeGetProfileApiCall(id.toString(), null); |
|
33 |
} |
|
34 |
|
|
35 |
/** |
|
36 |
* Overloaded version of getUserProfile to filter profiles |
|
37 |
* by language |
|
38 |
* UserProfile.notification might be returned as string instead of date |
|
39 |
* @param id user profile id |
|
40 |
* @param language language to filtery by |
|
41 |
*/ |
|
42 |
getUserProfileWithLanguage(id: number, language: Languages) { |
|
43 |
return this.makeGetProfileApiCall(id.toString(), language); |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* Returns profile of currently logged user |
|
48 |
* UserProfile.notification might be returned as string instead of date |
|
49 |
*/ |
|
50 |
getLoggedUserProfile() { |
|
51 |
return this.makeGetProfileApiCall('me', null); |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* Returns profile of currently logged user filtered by language |
|
56 |
* UserProfile.notification might be returned as string instead of date |
|
57 |
* @param language filter profile by language |
|
58 |
*/ |
|
59 |
getLoggedUserProfileWithLanguage(language: Languages) { |
|
60 |
return this.makeGetProfileApiCall('me', language); |
|
61 |
} |
|
62 |
|
|
63 | 24 |
/** |
64 | 25 |
* Returns vacation and sick days from the given date |
65 | 26 |
* for logged user |
... | ... | |
167 | 128 |
return this.makeDeleteCalendarApiCall(id, language); |
168 | 129 |
} |
169 | 130 |
|
170 |
/** |
|
171 |
* Získání profilu aktuálně přihlášeného uživatele nebo uživatele podle zadaného id. |
|
172 |
* GET /user/<{id} || me>/profile?[lang=<CZ,EN>] |
|
173 |
* @param id id of profile to get (number or 'me') |
|
174 |
* @param language filter by language |
|
175 |
*/ |
|
176 |
private makeGetProfileApiCall(id: string, language: string) { |
|
177 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
178 |
const options = {params: httpParams}; |
|
179 |
|
|
180 |
return this.http.get<UserProfile>(this._userUrl + id + '/profile', options) |
|
181 |
.pipe( |
|
182 |
catchError(err => this.handleError(err)) |
|
183 |
); |
|
184 |
} |
|
185 |
|
|
186 | 131 |
/** |
187 | 132 |
* Získání dovolené a sick days v zadaném období. Pokud není zadán parameter “to” vrátí všechny dovolené a sick days od “from”. Navíc umožňuje filtrovat pomocí statusu schválení. |
188 | 133 |
* GET /user/<{id} || me>/calendar?[lang=<CZ,EN>]&from=yyyy/mm/dd, [to=yyyy/mm/dd], [status=<ACCEPTED, PENDING, REJECTED>] |
webapp/src/app/services/api/users.service.ts | ||
---|---|---|
6 | 6 |
import {AuthorizationRequest, VacationRequest} from '../../models/requests.model'; |
7 | 7 |
import {Languages, ProfileStatus} from '../../enums/common.enum'; |
8 | 8 |
import {Observable} from 'rxjs'; |
9 |
import {UserBasicInformation} from '../../models/user.model'; |
|
9 |
import {UserBasicInformation, UserProfile} from '../../models/user.model';
|
|
10 | 10 |
import {MatSnackBar} from '@angular/material'; |
11 | 11 |
import {TranslateService} from '@ngx-translate/core'; |
12 | 12 |
|
... | ... | |
20 | 20 |
super(http, snackBar, translateService); |
21 | 21 |
} |
22 | 22 |
|
23 |
/** |
|
24 |
* Returns profile of currently logged user |
|
25 |
* UserProfile.notification might be returned as string instead of date |
|
26 |
*/ |
|
27 |
getLoggedUserProfile() { |
|
28 |
return this.makeGetProfileApiCall('current', null); |
|
29 |
} |
|
30 |
|
|
31 |
/** |
|
32 |
* Returns profile of currently logged user filtered by language |
|
33 |
* UserProfile.notification might be returned as string instead of date |
|
34 |
* @param language filter profile by language |
|
35 |
*/ |
|
36 |
getLoggedUserProfileWithLanguage(language: Languages) { |
|
37 |
return this.makeGetProfileApiCall('current', language); |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* Returns user profile if the user making this call |
|
42 |
* is logged as admin |
|
43 |
* UserProfile.notification might be returned as string instead of date |
|
44 |
* @param id user profile id |
|
45 |
*/ |
|
46 |
getUserProfile(id: number) { |
|
47 |
return this.makeGetProfileApiCall(id.toString(), null); |
|
48 |
} |
|
49 |
|
|
50 |
/** |
|
51 |
* Overloaded version of getUserProfile to filter profiles |
|
52 |
* by language |
|
53 |
* UserProfile.notification might be returned as string instead of date |
|
54 |
* @param id user profile id |
|
55 |
* @param language language to filtery by |
|
56 |
*/ |
|
57 |
getUserProfileWithLanguage(id: number, language: Languages) { |
|
58 |
return this.makeGetProfileApiCall(id.toString(), language); |
|
59 |
} |
|
60 |
|
|
23 | 61 |
/** |
24 | 62 |
* Returns all authorized users |
25 | 63 |
*/ |
... | ... | |
161 | 199 |
); |
162 | 200 |
} |
163 | 201 |
|
202 |
/** |
|
203 |
* Získání profilu aktuálně přihlášeného uživatele nebo uživatele podle zadaného id. |
|
204 |
* GET /user/<{id} || me>/profile?[lang=<CZ,EN>] |
|
205 |
* @param id id of profile to get (number or 'me') |
|
206 |
* @param language filter by language |
|
207 |
*/ |
|
208 |
private makeGetProfileApiCall(id: string, language: string) { |
|
209 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
210 |
const options = {params: httpParams}; |
|
211 |
|
|
212 |
return this.http.get<UserProfile>(this._usersUrl + "/" + id + '/profile', options) |
|
213 |
.pipe( |
|
214 |
catchError(err => this.handleError(err)) |
|
215 |
); |
|
216 |
} |
|
217 |
|
|
218 |
|
|
164 | 219 |
} |
webapp/src/app/services/tests/user.service.spec.ts | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import {UserService} from '../api/user.service'; |
4 | 4 |
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing'; |
5 |
import {Languages, RequestStatus, UserType, VacationType} from '../../enums/common.enum';
|
|
5 |
import {RequestStatus, VacationType} from '../../enums/common.enum';
|
|
6 | 6 |
import {environment} from '../../../environments/environment'; |
7 | 7 |
|
8 | 8 |
describe('UsersService', () => { |
... | ... | |
21 | 21 |
}); |
22 | 22 |
afterEach(() => httpMock.verify()); |
23 | 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 | 24 |
it('getLoggedUserCalendar', () => { |
81 | 25 |
const dummyData = [ |
82 | 26 |
{id: 1, date: '2000/10/10', from: '09:00', to: '13:00', type: 'VACATION'}, |
webapp/src/app/services/tests/users.service.spec.ts | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import {UsersService} from '../api/users.service'; |
4 | 4 |
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing'; |
5 |
import {RequestStatus, VacationType} from '../../enums/common.enum';
|
|
5 |
import {Languages, RequestStatus, UserType, VacationType} from '../../enums/common.enum';
|
|
6 | 6 |
import {environment} from '../../../environments/environment'; |
7 | 7 |
|
8 | 8 |
describe('UsersService', () => { |
... | ... | |
21 | 21 |
}); |
22 | 22 |
afterEach(() => httpMock.verify()); |
23 | 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 |
}); |
|
24 | 79 |
|
25 | 80 |
it('getAuthorizationRequests', () => { |
26 | 81 |
const dummyRequests = [ |
webapp/src/app/services/util/profile.service.ts | ||
---|---|---|
1 | 1 |
import {Injectable} from '@angular/core'; |
2 |
import {UserService} from '../api/user.service'; |
|
3 | 2 |
import {UserProfile} from '../../models/user.model'; |
4 | 3 |
import {Observable, of} from 'rxjs'; |
4 |
import {UsersService} from "../api/users.service"; |
|
5 | 5 |
|
6 | 6 |
@Injectable({ |
7 | 7 |
providedIn: 'root' |
... | ... | |
9 | 9 |
export class ProfileService { |
10 | 10 |
private profile: UserProfile; |
11 | 11 |
|
12 |
constructor(private userService: UserService) {
|
|
12 |
constructor(private usersService: UsersService) {
|
|
13 | 13 |
|
14 | 14 |
} |
15 | 15 |
|
16 |
//hardcoded username for now, to be replaced after proper authentication is in place |
|
17 |
public currentUserValue = "testuser@yoso.fi"; |
|
18 |
|
|
16 | 19 |
/** |
17 | 20 |
* Returns logged user profile if the server responds |
18 | 21 |
* with valid profile otherwise observer returns error |
... | ... | |
28 | 31 |
} |
29 | 32 |
|
30 | 33 |
return new Observable<UserProfile>((obs) => { |
31 |
this.userService.getLoggedUserProfile() |
|
34 |
this.usersService.getLoggedUserProfile()
|
|
32 | 35 |
.subscribe((userProfile: UserProfile) => { |
33 | 36 |
this.profile = {...userProfile}; |
34 | 37 |
obs.next(this.profile); |
Také k dispozici: Unified diff
re #37 make UI compatible with new User controller API