1
|
import { Injectable } from '@angular/core';
|
2
|
import { HttpClient } from '@angular/common/http';
|
3
|
import { BasicService } from './basic.service';
|
4
|
import { catchError } from 'rxjs/operators';
|
5
|
|
6
|
import { UserBasicInformation } from '../models/user-basic-information.model';
|
7
|
import { Requests } from '../models/requests.model';
|
8
|
|
9
|
@Injectable({
|
10
|
providedIn: 'root'
|
11
|
})
|
12
|
export class UsersService extends BasicService {
|
13
|
private usersUrl = this.baseUrl + '/users?status=';
|
14
|
private requestsUrl = this.baseUrl + '/users/requests?type=';
|
15
|
|
16
|
getAuthorizedUsers() {
|
17
|
return this.getUsersWithStatus('AUTHORIZED');
|
18
|
}
|
19
|
|
20
|
getPendingUsers() {
|
21
|
return this.getUsersWithStatus('PENDING');
|
22
|
}
|
23
|
|
24
|
getRejectedUsers() {
|
25
|
return this.getUsersWithStatus('REJECTED');
|
26
|
}
|
27
|
|
28
|
private getUsersWithStatus(status: string) {
|
29
|
return this.http.get<UserBasicInformation[]>(this.usersUrl + status)
|
30
|
.pipe(
|
31
|
catchError(err => this.handleError(err))
|
32
|
);
|
33
|
}
|
34
|
|
35
|
getVacationRequests() {
|
36
|
return this.getRequestsWithType('VACATION');
|
37
|
}
|
38
|
|
39
|
getAuthorizationRequests() {
|
40
|
return this.getRequestsWithType('AUTHORIZATION');
|
41
|
}
|
42
|
|
43
|
private getRequestsWithType(type: string) {
|
44
|
return this.http.get<Requests>(this.requestsUrl + type)
|
45
|
.pipe(
|
46
|
catchError(err => this.handleError(err))
|
47
|
);
|
48
|
}
|
49
|
|
50
|
constructor(protected http: HttpClient) {
|
51
|
super(http);
|
52
|
}
|
53
|
|
54
|
}
|