Revize 84a8db02
Přidáno uživatelem Hung Hoang před téměř 6 roky(ů)
webapp/src/app/days-off-approval/days-off-approval.component.ts | ||
---|---|---|
1 | 1 |
import { Component, EventEmitter, Output, Input } from '@angular/core'; |
2 |
import {Requests} from '../models/requests.model'; |
|
2 |
import {Requests} from '../models/requests.model'; // TODO
|
|
3 | 3 |
import {VacationType} from '../enums/common.enum'; |
4 | 4 |
|
5 | 5 |
@Component({ |
webapp/src/app/employees/employees-list.component.html | ||
---|---|---|
13 | 13 |
</tr> |
14 | 14 |
</thead> |
15 | 15 |
<tbody> |
16 |
<tr *ngFor="let user of users"> |
|
16 |
<tr *ngFor="let user of _users">
|
|
17 | 17 |
<th scope="row"> |
18 | 18 |
<img |
19 | 19 |
alt="photo" |
webapp/src/app/employees/employees-list.component.sass | ||
---|---|---|
14 | 14 |
.sickday |
15 | 15 |
background: #ffc0c0 |
16 | 16 |
border-radius: 40% |
17 |
justify-content: center |
|
17 | 18 |
|
18 | 19 |
.vacation |
19 | 20 |
background-color: #68b040 |
20 | 21 |
border-radius: 40% |
21 |
width: 40px |
|
22 |
justify-content: center |
webapp/src/app/employees/employees-list.component.ts | ||
---|---|---|
5 | 5 |
import {MatDialog} from '@angular/material'; |
6 | 6 |
import {EditEmployeeDialogComponent} from './edit-employee-dialog/edit-employee-dialog.component'; |
7 | 7 |
import {DayInfo, User} from './user.model'; |
8 |
import {AuthorizationRequest} from '../models/requests.model'; |
|
8 | 9 |
|
9 | 10 |
const daysOfWeek: string[] = [ |
10 | 11 |
'po', |
... | ... | |
71 | 72 |
|
72 | 73 |
for (const info of this._employeesBasicInformation) { |
73 | 74 |
user = new User(); |
74 |
user.name = info.name.first + ' ' + info.name.last;
|
|
75 |
user.name = info.firstName + ' ' + info.lastName;
|
|
75 | 76 |
user.id = info.id; |
76 | 77 |
user.imageLink = info.photo; |
77 | 78 |
user.dates = this.mapDays(info); |
... | ... | |
110 | 111 |
this.mapUsers(); |
111 | 112 |
console.log(this._users); |
112 | 113 |
}); |
114 |
|
|
115 |
|
|
116 |
let authorization: AuthorizationRequest[]; |
|
117 |
this.usersService.getAuthorizationRequests() |
|
118 |
.subscribe((data: AuthorizationRequest[]) => { |
|
119 |
authorization = { ...data}; |
|
120 |
|
|
121 |
console.log(authorization); |
|
122 |
}); |
|
113 | 123 |
} |
114 | 124 |
|
115 | 125 |
} |
webapp/src/app/enums/common.enum.ts | ||
---|---|---|
32 | 32 |
EMPLOYEE = 'EMPLOYEE', |
33 | 33 |
EMPLOYER = 'EMPLOYER', |
34 | 34 |
} |
35 |
|
|
36 |
export enum Languages { |
|
37 |
ENGLISH = 'EN', |
|
38 |
CZECH = 'CZ', |
|
39 |
} |
webapp/src/app/models/requests.model.ts | ||
---|---|---|
1 |
import {Time} from '@angular/common'; |
|
2 | 1 |
import {RequestStatus, VacationType} from '../enums/common.enum'; |
2 |
import {Time} from '@angular/common'; |
|
3 |
|
|
4 |
export interface VacationRequest { |
|
5 |
id: number; |
|
6 |
firstName: string; |
|
7 |
lastName: string; |
|
8 |
date: Date; |
|
9 |
from: Time; |
|
10 |
to: Time; |
|
11 |
type: VacationType; |
|
12 |
timestamp: Date; |
|
13 |
} |
|
14 |
|
|
15 |
|
|
16 |
export interface AuthorizationRequest { |
|
17 |
id: number; |
|
18 |
firstName: string; |
|
19 |
lastName: string; |
|
20 |
timestamp: Date; |
|
21 |
} |
|
3 | 22 |
|
23 |
/** |
|
24 |
* bude se mazat |
|
25 |
*/ |
|
4 | 26 |
export interface Requests { |
5 | 27 |
vacation: [ |
6 | 28 |
{ |
webapp/src/app/models/user-basic-information.model.ts | ||
---|---|---|
3 | 3 |
|
4 | 4 |
export interface UserBasicInformation { |
5 | 5 |
id: number; |
6 |
name: { |
|
7 |
first: string; |
|
8 |
last: string; |
|
9 |
}; |
|
6 |
firstName: string; |
|
7 |
lastName: string; |
|
10 | 8 |
photo: string; |
11 | 9 |
calendar: [ |
12 | 10 |
{ |
11 |
id: number, |
|
13 | 12 |
date: Date, |
14 | 13 |
from: Time, |
15 | 14 |
to: Time, |
webapp/src/app/services/users.service.spec.ts | ||
---|---|---|
1 |
import {TestBed} from '@angular/core/testing'; |
|
2 |
|
|
3 |
import {UsersService} from './users.service'; |
|
4 |
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing'; |
|
5 |
import {VacationRequest} from '../models/requests.model'; |
|
6 |
import {RequestStatus, VacationType} from '../enums/common.enum'; |
|
7 |
import {environment} from '../../environments/environment'; |
|
8 |
|
|
9 |
describe('UsersService', () => { |
|
10 |
let service: UsersService; |
|
11 |
let httpMock: HttpTestingController; |
|
12 |
const baseUrl: string = environment.apiUrl; |
|
13 |
|
|
14 |
beforeEach(() => { |
|
15 |
TestBed.configureTestingModule({ |
|
16 |
imports: [HttpClientTestingModule], |
|
17 |
providers: [UsersService] |
|
18 |
}); |
|
19 |
|
|
20 |
service = TestBed.get(UsersService); |
|
21 |
httpMock = TestBed.get(HttpTestingController); |
|
22 |
}); |
|
23 |
afterEach(() => httpMock.verify()); |
|
24 |
|
|
25 |
|
|
26 |
it('getAuthorizationRequests', () => { |
|
27 |
const dummyRequests = [ |
|
28 |
{ id: 1, firstName: 'Tomas', lastName: 'Novak', timestamp: '2019/05/24 21:55:11' }, |
|
29 |
{ id: 2, firstName: 'Tomas', lastName: 'Novak', timestamp: '2019/05/24 21:55:11' }, |
|
30 |
{ id: 3, firstName: 'Tomas', lastName: 'Novak', timestamp: '2019/05/24 21:55:11' }, |
|
31 |
{ id: 4, firstName: 'Tomas', lastName: 'Novak', timestamp: '2019/05/24 21:55:11' }, |
|
32 |
{ id: 5, firstName: 'Tomas', lastName: 'Novak', timestamp: '2019/05/24 21:55:11' } |
|
33 |
]; |
|
34 |
|
|
35 |
service.getAuthorizationRequests().subscribe((data: any) => { |
|
36 |
expect(data.length).toBe(5); |
|
37 |
expect(data[4].lastName).toBe('Novak'); |
|
38 |
expect(data[4].firstName).toBe('Tomas'); |
|
39 |
expect(data[4].id).toBe(5); |
|
40 |
expect(data[4].timestamp).toBeDefined(); |
|
41 |
}); |
|
42 |
|
|
43 |
const req = httpMock.expectOne(baseUrl + '/api/users/requests/authorization?'); |
|
44 |
expect(req.request.method).toBe('GET'); |
|
45 |
req.flush(dummyRequests); |
|
46 |
}); |
|
47 |
|
|
48 |
it('getVacationRequests', () => { |
|
49 |
const dummyRequests = [ |
|
50 |
{id: 1, firstName: 'Tomas', lastName: 'Novak', date: '2019/05/24', type: 'SICKDAY', timestamp: '2019/05/24 21:59:32'}, |
|
51 |
{ 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' }, |
|
52 |
{id: 3, firstName: 'Tomas', lastName: 'Novak', date: '2019/05/24', type: 'SICKDAY', timestamp: '2019/05/24 21:59:32'}, |
|
53 |
{ 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' }, |
|
54 |
{id: 5, firstName: 'Tomas', lastName: 'Novak', date: '2019/05/24', type: 'SICKDAY', timestamp: '2019/05/24 21:59:32'} |
|
55 |
]; |
|
56 |
service.getVacationRequests().subscribe((data: any) => { |
|
57 |
expect(data.length).toBe(5); |
|
58 |
|
|
59 |
expect(data[0].firstName).toBeDefined(); |
|
60 |
expect(data[0].lastName).toBeDefined(); |
|
61 |
|
|
62 |
expect(data[0].type).toBe(VacationType.SICKDAY); |
|
63 |
expect(data[0].to).toBeUndefined(); |
|
64 |
expect(data[0].from).toBeUndefined(); |
|
65 |
|
|
66 |
expect(data[1].type).toBe(VacationType.VACATION); |
|
67 |
expect(data[1].to).toBeDefined(); |
|
68 |
expect(data[1].from).toBeDefined(); |
|
69 |
}); |
|
70 |
|
|
71 |
const req = httpMock.expectOne(baseUrl + '/api/users/requests/vacation?'); |
|
72 |
expect(req.request.method).toBe('GET'); |
|
73 |
req.flush(dummyRequests); |
|
74 |
}); |
|
75 |
|
|
76 |
|
|
77 |
it('getAllUsers', () => { |
|
78 |
const dummyRequests = [ |
|
79 |
{ |
|
80 |
id: 1, |
|
81 |
firstName: 'Tomas', |
|
82 |
lastName: 'unknown', |
|
83 |
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg', |
|
84 |
calendar: [ |
|
85 |
{ |
|
86 |
id: 1, |
|
87 |
date: '2019/05/24', |
|
88 |
from: '09:00', |
|
89 |
to: '13:00', |
|
90 |
type: 'VACATION', |
|
91 |
status: 'ACCEPTED' |
|
92 |
}, |
|
93 |
{ |
|
94 |
id: 2, |
|
95 |
date: '2019/05/25', |
|
96 |
from: '09:00', |
|
97 |
to: '13:00', |
|
98 |
type: 'VACATION', |
|
99 |
status: 'ACCEPTED' |
|
100 |
} |
|
101 |
] |
|
102 |
}, |
|
103 |
{ |
|
104 |
id: 2, |
|
105 |
firstName: 'Tomas', |
|
106 |
lastName: 'unknown', |
|
107 |
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg', |
|
108 |
calendar: [ |
|
109 |
{ |
|
110 |
id: 1, |
|
111 |
date: '2019/05/24', |
|
112 |
from: '09:00', |
|
113 |
to: '13:00', |
|
114 |
type: 'VACATION', |
|
115 |
status: 'ACCEPTED' |
|
116 |
}, |
|
117 |
{ |
|
118 |
id: 2, |
|
119 |
date: '2019/05/25', |
|
120 |
from: '09:00', |
|
121 |
to: '13:00', |
|
122 |
type: 'VACATION', |
|
123 |
status: 'ACCEPTED' |
|
124 |
} |
|
125 |
] |
|
126 |
}, |
|
127 |
{ |
|
128 |
id: 3, |
|
129 |
firstName: 'Tomas', |
|
130 |
lastName: 'unknown', |
|
131 |
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg', |
|
132 |
calendar: [ |
|
133 |
{ |
|
134 |
id: 1, |
|
135 |
date: '2019/05/24', |
|
136 |
from: '09:00', |
|
137 |
to: '13:00', |
|
138 |
type: 'VACATION', |
|
139 |
status: 'ACCEPTED' |
|
140 |
}, |
|
141 |
{ |
|
142 |
id: 2, |
|
143 |
date: '2019/05/25', |
|
144 |
from: '09:00', |
|
145 |
to: '13:00', |
|
146 |
type: 'VACATION', |
|
147 |
status: 'ACCEPTED' |
|
148 |
} |
|
149 |
] |
|
150 |
}, |
|
151 |
{ |
|
152 |
id: 4, |
|
153 |
firstName: 'Tomas', |
|
154 |
lastName: 'unknown', |
|
155 |
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg', |
|
156 |
calendar: [ |
|
157 |
{ |
|
158 |
id: 1, |
|
159 |
date: '2019/05/24', |
|
160 |
from: '09:00', |
|
161 |
to: '13:00', |
|
162 |
type: 'VACATION', |
|
163 |
status: 'ACCEPTED' |
|
164 |
}, |
|
165 |
{ |
|
166 |
id: 2, |
|
167 |
date: '2019/05/25', |
|
168 |
from: '09:00', |
|
169 |
to: '13:00', |
|
170 |
type: 'VACATION', |
|
171 |
status: 'ACCEPTED' |
|
172 |
} |
|
173 |
] |
|
174 |
}, |
|
175 |
{ |
|
176 |
id: 5, |
|
177 |
firstName: 'Tomas', |
|
178 |
lastName: 'unknown', |
|
179 |
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg', |
|
180 |
calendar: [ |
|
181 |
{ |
|
182 |
id: 1, |
|
183 |
date: '2019/05/24', |
|
184 |
from: '09:00', |
|
185 |
to: '13:00', |
|
186 |
type: 'VACATION', |
|
187 |
status: 'ACCEPTED' |
|
188 |
}, |
|
189 |
{ |
|
190 |
id: 2, |
|
191 |
date: '2019/05/25', |
|
192 |
from: '09:00', |
|
193 |
to: '13:00', |
|
194 |
type: 'VACATION', |
|
195 |
status: 'ACCEPTED' |
|
196 |
} |
|
197 |
] |
|
198 |
} |
|
199 |
]; |
|
200 |
service.getUsers().subscribe((data: any) => { |
|
201 |
expect(data.length).toBe(5); |
|
202 |
expect(data[0].id).toBe(1); |
|
203 |
expect(data[0].firstName).toBeDefined(); |
|
204 |
expect(data[0].lastName).toBeDefined(); |
|
205 |
expect(data[0].photo).toBeDefined(); |
|
206 |
expect(data[0].calendar[0].type).toBe(VacationType.VACATION); |
|
207 |
expect(data[0].calendar[0].status).toBe(RequestStatus.ACCEPTED); |
|
208 |
expect(data[0].calendar[0].id).toBe(1); |
|
209 |
expect(data[0].calendar[1].id).toBe(2); |
|
210 |
}); |
|
211 |
|
|
212 |
const req = httpMock.expectOne(baseUrl + '/api/users?'); |
|
213 |
expect(req.request.method).toBe('GET'); |
|
214 |
req.flush(dummyRequests); |
|
215 |
}); |
|
216 |
|
|
217 |
}); |
webapp/src/app/services/users.service.ts | ||
---|---|---|
1 |
import { Injectable } from '@angular/core';
|
|
2 |
import { HttpClient } from '@angular/common/http';
|
|
3 |
import { BasicService } from './basic.service';
|
|
1 |
import {Injectable} from '@angular/core';
|
|
2 |
import {HttpClient} from '@angular/common/http';
|
|
3 |
import {BasicService} from './basic.service';
|
|
4 | 4 |
import {catchError} from 'rxjs/operators'; |
5 | 5 |
|
6 | 6 |
import {UserBasicInformation} from '../models/user-basic-information.model'; |
7 |
import { Requests } from '../models/requests.model';
|
|
8 |
import {ProfileStatus, RequestTypes} from '../enums/common.enum';
|
|
7 |
import {AuthorizationRequest, VacationRequest} from '../models/requests.model';
|
|
8 |
import {Languages, ProfileStatus} from '../enums/common.enum';
|
|
9 | 9 |
import {Observable} from 'rxjs'; |
10 | 10 |
|
11 | 11 |
@Injectable({ |
12 | 12 |
providedIn: 'root' |
13 | 13 |
}) |
14 | 14 |
export class UsersService extends BasicService { |
15 |
private _usersUrl = this.baseUrl + '/users?status='; |
|
16 |
private _requestsUrl = this.baseUrl + '/users/requests?type='; |
|
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?'; |
|
17 | 20 |
|
21 |
/** |
|
22 |
* Returns all authorized users |
|
23 |
*/ |
|
18 | 24 |
getAuthorizedUsers() { |
19 |
return this.getUsersWithStatus(ProfileStatus.AUTHORIZED);
|
|
25 |
return this.makeUsersApiCall(ProfileStatus.AUTHORIZED, '');
|
|
20 | 26 |
} |
21 | 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.makeUsersApiCall(ProfileStatus.AUTHORIZED, language); |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
38 |
* Returns all pending users |
|
39 |
*/ |
|
22 | 40 |
getPendingUsers() { |
23 |
return this.getUsersWithStatus(ProfileStatus.PENDING); |
|
41 |
return this.makeUsersApiCall(ProfileStatus.PENDING, ''); |
|
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.makeUsersApiCall(ProfileStatus.PENDING, language); |
|
24 | 51 |
} |
25 | 52 |
|
53 |
/** |
|
54 |
* Return all rejected users |
|
55 |
*/ |
|
26 | 56 |
getRejectedUsers() { |
27 |
return this.getUsersWithStatus(ProfileStatus.REJECTED);
|
|
57 |
return this.makeUsersApiCall(ProfileStatus.REJECTED, '');
|
|
28 | 58 |
} |
29 | 59 |
|
30 |
private getUsersWithStatus(status: string): Observable<UserBasicInformation[]> { |
|
31 |
console.log(this._usersUrl + status); |
|
32 |
return this.http.get<UserBasicInformation[]>(this._usersUrl + status) |
|
33 |
.pipe( |
|
34 |
catchError(err => this.handleError(err)) |
|
35 |
); |
|
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.makeUsersApiCall(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.makeUsersApiCall('', ''); |
|
36 | 75 |
} |
37 | 76 |
|
77 |
/** |
|
78 |
* Returns all vacation requests |
|
79 |
*/ |
|
38 | 80 |
getVacationRequests() { |
39 |
return this.getRequestsWithType(RequestTypes.VACATION); |
|
81 |
return this.makeVacationRequestsApiCall(''); |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* Returns vacations filtered by language |
|
86 |
* @param language filter by passed language |
|
87 |
*/ |
|
88 |
getVacationRequestsWithLanguage(language: Languages) { |
|
89 |
return this.makeVacationRequestsApiCall(language); |
|
40 | 90 |
} |
41 | 91 |
|
92 |
|
|
93 |
/** |
|
94 |
* Returns all authorization requests |
|
95 |
*/ |
|
42 | 96 |
getAuthorizationRequests() { |
43 |
return this.getRequestsWithType(RequestTypes.AUTHORIZATION); |
|
97 |
return this.makeAuthorizationRequestsApiCall(''); |
|
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.makeAuthorizationRequestsApiCall(language); |
|
107 |
} |
|
108 |
|
|
109 |
private makeAuthorizationRequestsApiCall(language: string) { |
|
110 |
const apiUrl: string = this.createApiUrl(this._authorizationRequestsUrl, '', language); |
|
111 |
|
|
112 |
return this.http.get<AuthorizationRequest[]>(apiUrl) |
|
113 |
.pipe( |
|
114 |
catchError(err => this.handleError(err)) |
|
115 |
); |
|
116 |
} |
|
117 |
|
|
118 |
private makeVacationRequestsApiCall(language: string) { |
|
119 |
const apiUrl: string = this.createApiUrl(this._vacationRequestsUrl, '', language); |
|
120 |
|
|
121 |
return this.http.get<VacationRequest[]>(apiUrl) |
|
122 |
.pipe( |
|
123 |
catchError(err => this.handleError(err)) |
|
124 |
); |
|
44 | 125 |
} |
45 | 126 |
|
46 |
private getRequestsWithType(type: string) { |
|
47 |
return this.http.get<Requests>(this._requestsUrl + type) |
|
127 |
private makeUsersApiCall(status: string, language: string): Observable<UserBasicInformation[]> { |
|
128 |
const apiUrl: string = this.createApiUrl(this._usersUrl, status, language); |
|
129 |
|
|
130 |
return this.http.get<UserBasicInformation[]>(apiUrl) |
|
48 | 131 |
.pipe( |
49 | 132 |
catchError(err => this.handleError(err)) |
50 | 133 |
); |
51 | 134 |
} |
52 | 135 |
|
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 |
|
|
53 | 149 |
constructor(protected http: HttpClient) { |
54 | 150 |
super(http); |
55 | 151 |
} |
Také k dispozici: Unified diff
Re#7493 Modified and tested Users service