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