]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/users/user.service.ts
Upgrade to rxjs 6
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / users / user.service.ts
CommitLineData
db400f44 1import { catchError, map } from 'rxjs/operators'
d592e0a9 2import { HttpClient } from '@angular/common/http'
63c4db6d 3import { Injectable } from '@angular/core'
8094a898 4import { UserCreate, UserUpdateMe } from '../../../../../shared'
63c4db6d
C
5import { environment } from '../../../environments/environment'
6import { RestExtractor } from '../rest'
629d8d6f
C
7
8@Injectable()
e2a2d6c8 9export class UserService {
63c4db6d 10 static BASE_USERS_URL = environment.apiUrl + '/api/v1/users/'
629d8d6f 11
df98563e 12 constructor (
d592e0a9 13 private authHttp: HttpClient,
de59c48f 14 private restExtractor: RestExtractor
db400f44
C
15 ) {
16 }
629d8d6f 17
df98563e 18 changePassword (newPassword: string) {
8094a898
C
19 const url = UserService.BASE_USERS_URL + 'me'
20 const body: UserUpdateMe = {
629d8d6f 21 password: newPassword
df98563e 22 }
629d8d6f 23
de59c48f 24 return this.authHttp.put(url, body)
db400f44
C
25 .pipe(
26 map(this.restExtractor.extractDataBool),
27 catchError(res => this.restExtractor.handleError(res))
28 )
629d8d6f 29 }
af5e743b 30
ed56ad11 31 updateMyProfile (profile: UserUpdateMe) {
8094a898 32 const url = UserService.BASE_USERS_URL + 'me'
af5e743b 33
ed56ad11 34 return this.authHttp.put(url, profile)
db400f44
C
35 .pipe(
36 map(this.restExtractor.extractDataBool),
37 catchError(res => this.restExtractor.handleError(res))
38 )
af5e743b 39 }
a184c71b 40
c5911fd3
C
41 changeAvatar (avatarForm: FormData) {
42 const url = UserService.BASE_USERS_URL + 'me/avatar/pick'
43
44 return this.authHttp.post(url, avatarForm)
db400f44 45 .pipe(catchError(this.restExtractor.handleError))
c5911fd3
C
46 }
47
4771e000 48 signup (userCreate: UserCreate) {
d592e0a9 49 return this.authHttp.post(UserService.BASE_USERS_URL + 'register', userCreate)
db400f44
C
50 .pipe(
51 map(this.restExtractor.extractDataBool),
52 catchError(res => this.restExtractor.handleError(res))
53 )
a184c71b 54 }
c5911fd3 55
ce5496d6
C
56 getMyVideoQuotaUsed () {
57 const url = UserService.BASE_USERS_URL + '/me/video-quota-used'
c5911fd3
C
58
59 return this.authHttp.get(url)
db400f44 60 .pipe(catchError(res => this.restExtractor.handleError(res)))
c5911fd3 61 }
ecb4e35f
C
62
63 askResetPassword (email: string) {
64 const url = UserService.BASE_USERS_URL + '/ask-reset-password'
65
66 return this.authHttp.post(url, { email })
db400f44
C
67 .pipe(
68 map(this.restExtractor.extractDataBool),
69 catchError(res => this.restExtractor.handleError(res))
70 )
ecb4e35f
C
71 }
72
73 resetPassword (userId: number, verificationString: string, password: string) {
74 const url = `${UserService.BASE_USERS_URL}/${userId}/reset-password`
75 const body = {
76 verificationString,
77 password
78 }
79
80 return this.authHttp.post(url, body)
db400f44
C
81 .pipe(
82 map(this.restExtractor.extractDataBool),
83 catchError(res => this.restExtractor.handleError(res))
84 )
ecb4e35f 85 }
629d8d6f 86}