1 |
41741550
|
Hung Hoang
|
import { Injectable } from '@angular/core';
|
2 |
|
|
import { HttpClient } from '@angular/common/http';
|
3 |
|
|
import { BasicService } from './basic.service';
|
4 |
c40c10c6
|
Hung Hoang
|
import {catchError, map} from 'rxjs/operators';
|
5 |
41741550
|
Hung Hoang
|
|
6 |
c40c10c6
|
Hung Hoang
|
import {UserBasicInformation} from '../models/user-basic-information.model';
|
7 |
41741550
|
Hung Hoang
|
import { Requests } from '../models/requests.model';
|
8 |
c40c10c6
|
Hung Hoang
|
import {ProfileStatus, RequestTypes} from '../enums/common.enum';
|
9 |
|
|
import {Observable} from 'rxjs';
|
10 |
41741550
|
Hung Hoang
|
|
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 |
c40c10c6
|
Hung Hoang
|
return this.getUsersWithStatus(ProfileStatus.AUTHORIZED);
|
20 |
41741550
|
Hung Hoang
|
}
|
21 |
|
|
|
22 |
|
|
getPendingUsers() {
|
23 |
c40c10c6
|
Hung Hoang
|
return this.getUsersWithStatus(ProfileStatus.PENDING);
|
24 |
41741550
|
Hung Hoang
|
}
|
25 |
|
|
|
26 |
|
|
getRejectedUsers() {
|
27 |
c40c10c6
|
Hung Hoang
|
return this.getUsersWithStatus(ProfileStatus.REJECTED);
|
28 |
41741550
|
Hung Hoang
|
}
|
29 |
|
|
|
30 |
c40c10c6
|
Hung Hoang
|
private getUsersWithStatus(status: string): Observable<UserBasicInformation[]> {
|
31 |
|
|
console.log(this.usersUrl + status);
|
32 |
41741550
|
Hung Hoang
|
return this.http.get<UserBasicInformation[]>(this.usersUrl + status)
|
33 |
|
|
.pipe(
|
34 |
|
|
catchError(err => this.handleError(err))
|
35 |
|
|
);
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
getVacationRequests() {
|
39 |
c40c10c6
|
Hung Hoang
|
return this.getRequestsWithType(RequestTypes.VACATION);
|
40 |
41741550
|
Hung Hoang
|
}
|
41 |
|
|
|
42 |
|
|
getAuthorizationRequests() {
|
43 |
c40c10c6
|
Hung Hoang
|
return this.getRequestsWithType(RequestTypes.AUTHORIZATION);
|
44 |
41741550
|
Hung Hoang
|
}
|
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 |
|
|
}
|