1 |
84a8db02
|
Hung Hoang
|
import {Injectable} from '@angular/core';
|
2 |
4bcef705
|
Hung Hoang
|
import {HttpClient, HttpParams} from '@angular/common/http';
|
3 |
84a8db02
|
Hung Hoang
|
import {BasicService} from './basic.service';
|
4 |
79d7de40
|
Hung Hoang
|
import {catchError} from 'rxjs/operators';
|
5 |
41741550
|
Hung Hoang
|
|
6 |
fd5ab42e
|
Hung Hoang
|
import {AuthorizationRequest, VacationRequest} from '../../models/requests.model';
|
7 |
|
|
import {Languages, ProfileStatus} from '../../enums/common.enum';
|
8 |
c40c10c6
|
Hung Hoang
|
import {Observable} from 'rxjs';
|
9 |
fd5ab42e
|
Hung Hoang
|
import {UserBasicInformation} from '../../models/user.model';
|
10 |
1d169f6d
|
Hung Hoang
|
import {MatSnackBar} from '@angular/material';
|
11 |
5d32cbea
|
Václav Jirák
|
import {TranslateService} from '@ngx-translate/core';
|
12 |
41741550
|
Hung Hoang
|
|
13 |
|
|
@Injectable({
|
14 |
|
|
providedIn: 'root'
|
15 |
|
|
})
|
16 |
|
|
export class UsersService extends BasicService {
|
17 |
4bcef705
|
Hung Hoang
|
private _usersUrl = this.baseUrl + '/api/users';
|
18 |
|
|
|
19 |
5d32cbea
|
Václav Jirák
|
constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) {
|
20 |
|
|
super(http, snackBar, translateService);
|
21 |
4bcef705
|
Hung Hoang
|
}
|
22 |
41741550
|
Hung Hoang
|
|
23 |
84a8db02
|
Hung Hoang
|
/**
|
24 |
|
|
* Returns all authorized users
|
25 |
|
|
*/
|
26 |
41741550
|
Hung Hoang
|
getAuthorizedUsers() {
|
27 |
7479e470
|
Hung Hoang
|
return this.makeGetUsersApiCall(null, ProfileStatus.AUTHORIZED);
|
28 |
41741550
|
Hung Hoang
|
}
|
29 |
|
|
|
30 |
84a8db02
|
Hung Hoang
|
/**
|
31 |
|
|
* Returns all authorized users with specified language
|
32 |
|
|
* overloaded version of getAuthorizedUsers
|
33 |
|
|
* @param language filter users based on language
|
34 |
|
|
*/
|
35 |
|
|
getAuthorizedUsersWithLanguage(language: Languages) {
|
36 |
7479e470
|
Hung Hoang
|
return this.makeGetUsersApiCall(language, ProfileStatus.AUTHORIZED);
|
37 |
84a8db02
|
Hung Hoang
|
}
|
38 |
|
|
|
39 |
|
|
/**
|
40 |
|
|
* Returns all pending users
|
41 |
|
|
*/
|
42 |
41741550
|
Hung Hoang
|
getPendingUsers() {
|
43 |
7479e470
|
Hung Hoang
|
return this.makeGetUsersApiCall(null, ProfileStatus.PENDING);
|
44 |
84a8db02
|
Hung Hoang
|
}
|
45 |
|
|
|
46 |
|
|
/**
|
47 |
|
|
* Returns all pending users with specified language
|
48 |
|
|
* overloaded version of getPendingUsers
|
49 |
|
|
* @param language filter users based on language
|
50 |
|
|
*/
|
51 |
|
|
getPendingUsersWithLanguage(language: Languages) {
|
52 |
7479e470
|
Hung Hoang
|
return this.makeGetUsersApiCall(language, ProfileStatus.PENDING);
|
53 |
41741550
|
Hung Hoang
|
}
|
54 |
|
|
|
55 |
84a8db02
|
Hung Hoang
|
/**
|
56 |
|
|
* Return all rejected users
|
57 |
|
|
*/
|
58 |
41741550
|
Hung Hoang
|
getRejectedUsers() {
|
59 |
7479e470
|
Hung Hoang
|
return this.makeGetUsersApiCall(null, ProfileStatus.REJECTED);
|
60 |
41741550
|
Hung Hoang
|
}
|
61 |
|
|
|
62 |
84a8db02
|
Hung Hoang
|
/**
|
63 |
|
|
* Returns all rejected users with specified language
|
64 |
|
|
* overloaded version of getRejectedUsers
|
65 |
|
|
* @param language filter users based on language
|
66 |
|
|
*/
|
67 |
|
|
getRejectedUsersWithLanguage(language: Languages) {
|
68 |
7479e470
|
Hung Hoang
|
return this.makeGetUsersApiCall(language, ProfileStatus.REJECTED);
|
69 |
84a8db02
|
Hung Hoang
|
}
|
70 |
|
|
|
71 |
|
|
/**
|
72 |
|
|
* Default api call which returns all users in the database
|
73 |
|
|
* regardless of language and status
|
74 |
|
|
*/
|
75 |
|
|
getUsers() {
|
76 |
7479e470
|
Hung Hoang
|
return this.makeGetUsersApiCall();
|
77 |
41741550
|
Hung Hoang
|
}
|
78 |
|
|
|
79 |
84a8db02
|
Hung Hoang
|
/**
|
80 |
7479e470
|
Hung Hoang
|
* Returns all vacation requests specified by status, if status
|
81 |
|
|
* is not specified, returns all vacation requests
|
82 |
|
|
* @param status optional vacation request status
|
83 |
84a8db02
|
Hung Hoang
|
*/
|
84 |
7479e470
|
Hung Hoang
|
getVacationRequests(status?: string) {
|
85 |
|
|
return this.makeGetVacationRequestsApiCall( null, status);
|
86 |
84a8db02
|
Hung Hoang
|
}
|
87 |
|
|
|
88 |
|
|
/**
|
89 |
|
|
* Returns vacations filtered by language
|
90 |
|
|
* @param language filter by passed language
|
91 |
7479e470
|
Hung Hoang
|
* @param status optionalvacation request status
|
92 |
84a8db02
|
Hung Hoang
|
*/
|
93 |
7479e470
|
Hung Hoang
|
getVacationRequestsWithLanguage(language: Languages, status?: string) {
|
94 |
|
|
return this.makeGetVacationRequestsApiCall(language, status);
|
95 |
41741550
|
Hung Hoang
|
}
|
96 |
|
|
|
97 |
84a8db02
|
Hung Hoang
|
|
98 |
|
|
/**
|
99 |
|
|
* Returns all authorization requests
|
100 |
7479e470
|
Hung Hoang
|
* @param status optional authorization request status
|
101 |
84a8db02
|
Hung Hoang
|
*/
|
102 |
7479e470
|
Hung Hoang
|
getAuthorizationRequests(status?: string) {
|
103 |
|
|
return this.makeGetAuthorizationRequestsApiCall(null, status);
|
104 |
84a8db02
|
Hung Hoang
|
}
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
/**
|
108 |
|
|
* Returns authorization requests filtered by language
|
109 |
|
|
* @param language filter by passed language
|
110 |
7479e470
|
Hung Hoang
|
* @param status optional authorization request status
|
111 |
84a8db02
|
Hung Hoang
|
*/
|
112 |
7479e470
|
Hung Hoang
|
getAuthorizationRequestsWithLanguage(language: Languages, status?: string) {
|
113 |
|
|
return this.makeGetAuthorizationRequestsApiCall(language, status);
|
114 |
84a8db02
|
Hung Hoang
|
}
|
115 |
|
|
|
116 |
4bcef705
|
Hung Hoang
|
/**
|
117 |
|
|
* Získání žádostí o autorizaci všech uživatelů s možností filtrace pomocí úrovně schválení.
|
118 |
|
|
* GET /users/requests/authorization?[lang=<CZ,EN>]&[status=<ACCEPTED, PENDING, REJECTED>
|
119 |
|
|
* @param language filter by language
|
120 |
7479e470
|
Hung Hoang
|
* @param status optional authorization request status
|
121 |
4bcef705
|
Hung Hoang
|
*/
|
122 |
7479e470
|
Hung Hoang
|
private makeGetAuthorizationRequestsApiCall(language?: string, statusReq?: string) {
|
123 |
|
|
const httpParams: HttpParams = this.createParams({lang: language, status: statusReq});
|
124 |
4bcef705
|
Hung Hoang
|
const options = {params: httpParams};
|
125 |
84a8db02
|
Hung Hoang
|
|
126 |
4bcef705
|
Hung Hoang
|
return this.http.get<AuthorizationRequest[]>(this._usersUrl + '/requests/authorization', options)
|
127 |
84a8db02
|
Hung Hoang
|
.pipe(
|
128 |
|
|
catchError(err => this.handleError(err))
|
129 |
|
|
);
|
130 |
|
|
}
|
131 |
|
|
|
132 |
4bcef705
|
Hung Hoang
|
/**
|
133 |
|
|
* Získání žádostí o dovolené a sick days všech uživatelů s možností filtrace pomocí úrovně schválení.
|
134 |
|
|
* GET /users/requests/vacation? [lang=<CZ,EN>]&[status=<ACCEPTED, PENDING, REJECTED>]
|
135 |
|
|
* @param language filter by language
|
136 |
7479e470
|
Hung Hoang
|
* @param status vacation request status
|
137 |
4bcef705
|
Hung Hoang
|
*/
|
138 |
7479e470
|
Hung Hoang
|
private makeGetVacationRequestsApiCall(language?: string, statusReq?: string) {
|
139 |
|
|
const httpParams: HttpParams = this.createParams({lang: language, status: statusReq});
|
140 |
4bcef705
|
Hung Hoang
|
const options = {params: httpParams};
|
141 |
84a8db02
|
Hung Hoang
|
|
142 |
4bcef705
|
Hung Hoang
|
return this.http.get<VacationRequest[]>(this._usersUrl + '/requests/vacation', options)
|
143 |
84a8db02
|
Hung Hoang
|
.pipe(
|
144 |
|
|
catchError(err => this.handleError(err))
|
145 |
|
|
);
|
146 |
41741550
|
Hung Hoang
|
}
|
147 |
|
|
|
148 |
4bcef705
|
Hung Hoang
|
/**
|
149 |
|
|
* Získání všech uživatelů s možností filtrace pomocí statusu
|
150 |
|
|
* GET /users?[lang=<CZ,EN>]&[status=<ACCEPTED, PENDING, REJECTED>]
|
151 |
|
|
* @param status filter by status
|
152 |
|
|
* @param language filter by language
|
153 |
|
|
*/
|
154 |
7479e470
|
Hung Hoang
|
private makeGetUsersApiCall(language?: string, status?: string): Observable<UserBasicInformation[]> {
|
155 |
4bcef705
|
Hung Hoang
|
const httpParams: HttpParams = this.createParams({lang: language, status});
|
156 |
|
|
const options = {params: httpParams};
|
157 |
84a8db02
|
Hung Hoang
|
|
158 |
4bcef705
|
Hung Hoang
|
return this.http.get<UserBasicInformation[]>(this._usersUrl, options)
|
159 |
41741550
|
Hung Hoang
|
.pipe(
|
160 |
|
|
catchError(err => this.handleError(err))
|
161 |
|
|
);
|
162 |
|
|
}
|
163 |
|
|
|
164 |
|
|
}
|