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 |
c40c10c6
|
Hung Hoang
|
import {UserBasicInformation} from '../models/user-basic-information.model';
|
7 |
84a8db02
|
Hung Hoang
|
import {AuthorizationRequest, VacationRequest} from '../models/requests.model';
|
8 |
|
|
import {Languages, ProfileStatus} from '../enums/common.enum';
|
9 |
c40c10c6
|
Hung Hoang
|
import {Observable} from 'rxjs';
|
10 |
41741550
|
Hung Hoang
|
|
11 |
|
|
@Injectable({
|
12 |
|
|
providedIn: 'root'
|
13 |
|
|
})
|
14 |
|
|
export class UsersService extends BasicService {
|
15 |
4bcef705
|
Hung Hoang
|
private _usersUrl = this.baseUrl + '/api/users';
|
16 |
|
|
|
17 |
|
|
constructor(protected http: HttpClient) {
|
18 |
|
|
super(http);
|
19 |
|
|
}
|
20 |
41741550
|
Hung Hoang
|
|
21 |
84a8db02
|
Hung Hoang
|
/**
|
22 |
|
|
* Returns all authorized users
|
23 |
|
|
*/
|
24 |
41741550
|
Hung Hoang
|
getAuthorizedUsers() {
|
25 |
4bcef705
|
Hung Hoang
|
return this.makeGetUsersApiCall(ProfileStatus.AUTHORIZED, null);
|
26 |
41741550
|
Hung Hoang
|
}
|
27 |
|
|
|
28 |
84a8db02
|
Hung Hoang
|
/**
|
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 |
4bcef705
|
Hung Hoang
|
return this.makeGetUsersApiCall(ProfileStatus.AUTHORIZED, language);
|
35 |
84a8db02
|
Hung Hoang
|
}
|
36 |
|
|
|
37 |
|
|
/**
|
38 |
|
|
* Returns all pending users
|
39 |
|
|
*/
|
40 |
41741550
|
Hung Hoang
|
getPendingUsers() {
|
41 |
4bcef705
|
Hung Hoang
|
return this.makeGetUsersApiCall(ProfileStatus.PENDING, null);
|
42 |
84a8db02
|
Hung Hoang
|
}
|
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 |
4bcef705
|
Hung Hoang
|
return this.makeGetUsersApiCall(ProfileStatus.PENDING, language);
|
51 |
41741550
|
Hung Hoang
|
}
|
52 |
|
|
|
53 |
84a8db02
|
Hung Hoang
|
/**
|
54 |
|
|
* Return all rejected users
|
55 |
|
|
*/
|
56 |
41741550
|
Hung Hoang
|
getRejectedUsers() {
|
57 |
4bcef705
|
Hung Hoang
|
return this.makeGetUsersApiCall(ProfileStatus.REJECTED, null);
|
58 |
41741550
|
Hung Hoang
|
}
|
59 |
|
|
|
60 |
84a8db02
|
Hung Hoang
|
/**
|
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 |
4bcef705
|
Hung Hoang
|
return this.makeGetUsersApiCall(ProfileStatus.REJECTED, language);
|
67 |
84a8db02
|
Hung Hoang
|
}
|
68 |
|
|
|
69 |
|
|
/**
|
70 |
|
|
* Default api call which returns all users in the database
|
71 |
|
|
* regardless of language and status
|
72 |
|
|
*/
|
73 |
|
|
getUsers() {
|
74 |
4bcef705
|
Hung Hoang
|
return this.makeGetUsersApiCall(null, null);
|
75 |
41741550
|
Hung Hoang
|
}
|
76 |
|
|
|
77 |
84a8db02
|
Hung Hoang
|
/**
|
78 |
|
|
* Returns all vacation requests
|
79 |
|
|
*/
|
80 |
41741550
|
Hung Hoang
|
getVacationRequests() {
|
81 |
4bcef705
|
Hung Hoang
|
return this.makeGetVacationRequestsApiCall(null);
|
82 |
84a8db02
|
Hung Hoang
|
}
|
83 |
|
|
|
84 |
|
|
/**
|
85 |
|
|
* Returns vacations filtered by language
|
86 |
|
|
* @param language filter by passed language
|
87 |
|
|
*/
|
88 |
|
|
getVacationRequestsWithLanguage(language: Languages) {
|
89 |
4bcef705
|
Hung Hoang
|
return this.makeGetVacationRequestsApiCall(language);
|
90 |
41741550
|
Hung Hoang
|
}
|
91 |
|
|
|
92 |
84a8db02
|
Hung Hoang
|
|
93 |
|
|
/**
|
94 |
|
|
* Returns all authorization requests
|
95 |
|
|
*/
|
96 |
41741550
|
Hung Hoang
|
getAuthorizationRequests() {
|
97 |
4bcef705
|
Hung Hoang
|
return this.makeGetAuthorizationRequestsApiCall(null);
|
98 |
84a8db02
|
Hung Hoang
|
}
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
/**
|
102 |
|
|
* Returns authorization requests filtered by language
|
103 |
|
|
* @param language filter by passed language
|
104 |
|
|
*/
|
105 |
|
|
getAuthorizationRequestsWithLanguage(language: Languages) {
|
106 |
4bcef705
|
Hung Hoang
|
return this.makeGetAuthorizationRequestsApiCall(language);
|
107 |
84a8db02
|
Hung Hoang
|
}
|
108 |
|
|
|
109 |
4bcef705
|
Hung Hoang
|
/**
|
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 |
84a8db02
|
Hung Hoang
|
|
118 |
4bcef705
|
Hung Hoang
|
return this.http.get<AuthorizationRequest[]>(this._usersUrl + '/requests/authorization', options)
|
119 |
84a8db02
|
Hung Hoang
|
.pipe(
|
120 |
|
|
catchError(err => this.handleError(err))
|
121 |
|
|
);
|
122 |
|
|
}
|
123 |
|
|
|
124 |
4bcef705
|
Hung Hoang
|
/**
|
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 |
84a8db02
|
Hung Hoang
|
|
133 |
4bcef705
|
Hung Hoang
|
return this.http.get<VacationRequest[]>(this._usersUrl + '/requests/vacation', options)
|
134 |
84a8db02
|
Hung Hoang
|
.pipe(
|
135 |
|
|
catchError(err => this.handleError(err))
|
136 |
|
|
);
|
137 |
41741550
|
Hung Hoang
|
}
|
138 |
|
|
|
139 |
4bcef705
|
Hung Hoang
|
/**
|
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 |
84a8db02
|
Hung Hoang
|
|
149 |
4bcef705
|
Hung Hoang
|
return this.http.get<UserBasicInformation[]>(this._usersUrl, options)
|
150 |
41741550
|
Hung Hoang
|
.pipe(
|
151 |
|
|
catchError(err => this.handleError(err))
|
152 |
|
|
);
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
}
|