1 |
84a8db02
|
Hung Hoang
|
import {Injectable} from '@angular/core';
|
2 |
|
|
import {HttpClient} from '@angular/common/http';
|
3 |
|
|
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 |
84a8db02
|
Hung Hoang
|
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?';
|
20 |
41741550
|
Hung Hoang
|
|
21 |
84a8db02
|
Hung Hoang
|
/**
|
22 |
|
|
* Returns all authorized users
|
23 |
|
|
*/
|
24 |
41741550
|
Hung Hoang
|
getAuthorizedUsers() {
|
25 |
84a8db02
|
Hung Hoang
|
return this.makeUsersApiCall(ProfileStatus.AUTHORIZED, '');
|
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 |
|
|
return this.makeUsersApiCall(ProfileStatus.AUTHORIZED, language);
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
/**
|
38 |
|
|
* Returns all pending users
|
39 |
|
|
*/
|
40 |
41741550
|
Hung Hoang
|
getPendingUsers() {
|
41 |
84a8db02
|
Hung Hoang
|
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);
|
51 |
41741550
|
Hung Hoang
|
}
|
52 |
|
|
|
53 |
84a8db02
|
Hung Hoang
|
/**
|
54 |
|
|
* Return all rejected users
|
55 |
|
|
*/
|
56 |
41741550
|
Hung Hoang
|
getRejectedUsers() {
|
57 |
84a8db02
|
Hung Hoang
|
return this.makeUsersApiCall(ProfileStatus.REJECTED, '');
|
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 |
|
|
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('', '');
|
75 |
41741550
|
Hung Hoang
|
}
|
76 |
|
|
|
77 |
84a8db02
|
Hung Hoang
|
/**
|
78 |
|
|
* Returns all vacation requests
|
79 |
|
|
*/
|
80 |
41741550
|
Hung Hoang
|
getVacationRequests() {
|
81 |
84a8db02
|
Hung Hoang
|
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);
|
90 |
41741550
|
Hung Hoang
|
}
|
91 |
|
|
|
92 |
84a8db02
|
Hung Hoang
|
|
93 |
|
|
/**
|
94 |
|
|
* Returns all authorization requests
|
95 |
|
|
*/
|
96 |
41741550
|
Hung Hoang
|
getAuthorizationRequests() {
|
97 |
84a8db02
|
Hung Hoang
|
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 |
|
|
);
|
125 |
41741550
|
Hung Hoang
|
}
|
126 |
|
|
|
127 |
84a8db02
|
Hung Hoang
|
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)
|
131 |
41741550
|
Hung Hoang
|
.pipe(
|
132 |
|
|
catchError(err => this.handleError(err))
|
133 |
|
|
);
|
134 |
|
|
}
|
135 |
|
|
|
136 |
84a8db02
|
Hung Hoang
|
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 |
|
|
|
149 |
41741550
|
Hung Hoang
|
constructor(protected http: HttpClient) {
|
150 |
|
|
super(http);
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
}
|