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