1 import { catchError, map } from 'rxjs/operators'
2 import { HttpClient } from '@angular/common/http'
3 import { Injectable } from '@angular/core'
4 import { UserCreate, UserUpdateMe } from '../../../../../shared'
5 import { environment } from '../../../environments/environment'
6 import { RestExtractor } from '../rest'
9 export class UserService {
10 static BASE_USERS_URL = environment.apiUrl + '/api/v1/users/'
13 private authHttp: HttpClient,
14 private restExtractor: RestExtractor
18 changePassword (newPassword: string) {
19 const url = UserService.BASE_USERS_URL + 'me'
20 const body: UserUpdateMe = {
24 return this.authHttp.put(url, body)
26 map(this.restExtractor.extractDataBool),
27 catchError(res => this.restExtractor.handleError(res))
31 updateMyProfile (profile: UserUpdateMe) {
32 const url = UserService.BASE_USERS_URL + 'me'
34 return this.authHttp.put(url, profile)
36 map(this.restExtractor.extractDataBool),
37 catchError(res => this.restExtractor.handleError(res))
41 changeAvatar (avatarForm: FormData) {
42 const url = UserService.BASE_USERS_URL + 'me/avatar/pick'
44 return this.authHttp.post(url, avatarForm)
45 .pipe(catchError(this.restExtractor.handleError))
48 signup (userCreate: UserCreate) {
49 return this.authHttp.post(UserService.BASE_USERS_URL + 'register', userCreate)
51 map(this.restExtractor.extractDataBool),
52 catchError(res => this.restExtractor.handleError(res))
56 getMyVideoQuotaUsed () {
57 const url = UserService.BASE_USERS_URL + '/me/video-quota-used'
59 return this.authHttp.get(url)
60 .pipe(catchError(res => this.restExtractor.handleError(res)))
63 askResetPassword (email: string) {
64 const url = UserService.BASE_USERS_URL + '/ask-reset-password'
66 return this.authHttp.post(url, { email })
68 map(this.restExtractor.extractDataBool),
69 catchError(res => this.restExtractor.handleError(res))
73 resetPassword (userId: number, verificationString: string, password: string) {
74 const url = `${UserService.BASE_USERS_URL}/${userId}/reset-password`
80 return this.authHttp.post(url, body)
82 map(this.restExtractor.extractDataBool),
83 catchError(res => this.restExtractor.handleError(res))