diff options
author | Chocobozzz <me@florianbigard.com> | 2018-05-15 11:55:51 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-05-16 09:42:54 +0200 |
commit | db400f447a9f7aae1c56fa25396e93069744483f (patch) | |
tree | f45af832a5d3f4eebafd2f885b7413d9f84fa374 /client/src/app/+admin/users/shared | |
parent | 54c3a22faa04bf13eea37f39be9149fc5eb95737 (diff) | |
download | PeerTube-db400f447a9f7aae1c56fa25396e93069744483f.tar.gz PeerTube-db400f447a9f7aae1c56fa25396e93069744483f.tar.zst PeerTube-db400f447a9f7aae1c56fa25396e93069744483f.zip |
Upgrade to rxjs 6
Diffstat (limited to 'client/src/app/+admin/users/shared')
-rw-r--r-- | client/src/app/+admin/users/shared/user.service.ts | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/client/src/app/+admin/users/shared/user.service.ts b/client/src/app/+admin/users/shared/user.service.ts index 6536546fb..578cd98c3 100644 --- a/client/src/app/+admin/users/shared/user.service.ts +++ b/client/src/app/+admin/users/shared/user.service.ts | |||
@@ -1,10 +1,9 @@ | |||
1 | import { catchError, map } from 'rxjs/operators' | ||
1 | import { HttpClient, HttpParams } from '@angular/common/http' | 2 | import { HttpClient, HttpParams } from '@angular/common/http' |
2 | import { Injectable } from '@angular/core' | 3 | import { Injectable } from '@angular/core' |
3 | import { BytesPipe } from 'ngx-pipes' | 4 | import { BytesPipe } from 'ngx-pipes' |
4 | import { SortMeta } from 'primeng/components/common/sortmeta' | 5 | import { SortMeta } from 'primeng/components/common/sortmeta' |
5 | import 'rxjs/add/operator/catch' | 6 | import { Observable } from 'rxjs' |
6 | import 'rxjs/add/operator/map' | ||
7 | import { Observable } from 'rxjs/Observable' | ||
8 | import { ResultList, UserCreate, UserUpdate } from '../../../../../../shared' | 7 | import { ResultList, UserCreate, UserUpdate } from '../../../../../../shared' |
9 | import { environment } from '../../../../environments/environment' | 8 | import { environment } from '../../../../environments/environment' |
10 | import { RestExtractor, RestPagination, RestService, User } from '../../../shared' | 9 | import { RestExtractor, RestPagination, RestService, User } from '../../../shared' |
@@ -18,23 +17,28 @@ export class UserService { | |||
18 | private authHttp: HttpClient, | 17 | private authHttp: HttpClient, |
19 | private restService: RestService, | 18 | private restService: RestService, |
20 | private restExtractor: RestExtractor | 19 | private restExtractor: RestExtractor |
21 | ) {} | 20 | ) { |
21 | } | ||
22 | 22 | ||
23 | addUser (userCreate: UserCreate) { | 23 | addUser (userCreate: UserCreate) { |
24 | return this.authHttp.post(UserService.BASE_USERS_URL, userCreate) | 24 | return this.authHttp.post(UserService.BASE_USERS_URL, userCreate) |
25 | .map(this.restExtractor.extractDataBool) | 25 | .pipe( |
26 | .catch(err => this.restExtractor.handleError(err)) | 26 | map(this.restExtractor.extractDataBool), |
27 | catchError(err => this.restExtractor.handleError(err)) | ||
28 | ) | ||
27 | } | 29 | } |
28 | 30 | ||
29 | updateUser (userId: number, userUpdate: UserUpdate) { | 31 | updateUser (userId: number, userUpdate: UserUpdate) { |
30 | return this.authHttp.put(UserService.BASE_USERS_URL + userId, userUpdate) | 32 | return this.authHttp.put(UserService.BASE_USERS_URL + userId, userUpdate) |
31 | .map(this.restExtractor.extractDataBool) | 33 | .pipe( |
32 | .catch(err => this.restExtractor.handleError(err)) | 34 | map(this.restExtractor.extractDataBool), |
35 | catchError(err => this.restExtractor.handleError(err)) | ||
36 | ) | ||
33 | } | 37 | } |
34 | 38 | ||
35 | getUser (userId: number) { | 39 | getUser (userId: number) { |
36 | return this.authHttp.get<User>(UserService.BASE_USERS_URL + userId) | 40 | return this.authHttp.get<User>(UserService.BASE_USERS_URL + userId) |
37 | .catch(err => this.restExtractor.handleError(err)) | 41 | .pipe(catchError(err => this.restExtractor.handleError(err))) |
38 | } | 42 | } |
39 | 43 | ||
40 | getUsers (pagination: RestPagination, sort: SortMeta): Observable<ResultList<User>> { | 44 | getUsers (pagination: RestPagination, sort: SortMeta): Observable<ResultList<User>> { |
@@ -42,13 +46,16 @@ export class UserService { | |||
42 | params = this.restService.addRestGetParams(params, pagination, sort) | 46 | params = this.restService.addRestGetParams(params, pagination, sort) |
43 | 47 | ||
44 | return this.authHttp.get<ResultList<User>>(UserService.BASE_USERS_URL, { params }) | 48 | return this.authHttp.get<ResultList<User>>(UserService.BASE_USERS_URL, { params }) |
45 | .map(res => this.restExtractor.convertResultListDateToHuman(res)) | 49 | .pipe( |
46 | .map(res => this.restExtractor.applyToResultListData(res, this.formatUser.bind(this))) | 50 | map(res => this.restExtractor.convertResultListDateToHuman(res)), |
47 | .catch(err => this.restExtractor.handleError(err)) | 51 | map(res => this.restExtractor.applyToResultListData(res, this.formatUser.bind(this))), |
52 | catchError(err => this.restExtractor.handleError(err)) | ||
53 | ) | ||
48 | } | 54 | } |
49 | 55 | ||
50 | removeUser (user: User) { | 56 | removeUser (user: User) { |
51 | return this.authHttp.delete(UserService.BASE_USERS_URL + user.id) | 57 | return this.authHttp.delete(UserService.BASE_USERS_URL + user.id) |
58 | .pipe(catchError(err => this.restExtractor.handleError(err))) | ||
52 | } | 59 | } |
53 | 60 | ||
54 | private formatUser (user: User) { | 61 | private formatUser (user: User) { |