PeerTube/client/src/app/shared/users/user.service.ts

43 lines
1.3 KiB
TypeScript
Raw Normal View History

import { Injectable } from '@angular/core'
import { HttpClient } from '@angular/common/http'
import 'rxjs/add/operator/catch'
import 'rxjs/add/operator/map'
2016-08-05 18:04:08 +02:00
import { RestExtractor } from '../rest'
2017-09-05 21:29:39 +02:00
import { UserCreate, UserUpdateMe } from '../../../../../shared'
2016-08-05 18:04:08 +02:00
@Injectable()
export class UserService {
static BASE_USERS_URL = API_URL + '/api/v1/users/'
2016-08-05 18:04:08 +02:00
constructor (
private authHttp: HttpClient,
private restExtractor: RestExtractor
) {}
2016-08-05 18:04:08 +02:00
changePassword (newPassword: string) {
2017-09-05 21:29:39 +02:00
const url = UserService.BASE_USERS_URL + 'me'
const body: UserUpdateMe = {
2016-08-05 18:04:08 +02:00
password: newPassword
}
2016-08-05 18:04:08 +02:00
return this.authHttp.put(url, body)
.map(this.restExtractor.extractDataBool)
.catch(res => this.restExtractor.handleError(res))
2016-08-05 18:04:08 +02:00
}
2017-09-05 21:29:39 +02:00
updateMyDetails (details: UserUpdateMe) {
const url = UserService.BASE_USERS_URL + 'me'
return this.authHttp.put(url, details)
.map(this.restExtractor.extractDataBool)
.catch(res => this.restExtractor.handleError(res))
}
2017-04-10 20:29:33 +02:00
signup (userCreate: UserCreate) {
return this.authHttp.post(UserService.BASE_USERS_URL + 'register', userCreate)
2017-04-10 20:29:33 +02:00
.map(this.restExtractor.extractDataBool)
.catch(res => this.restExtractor.handleError(res))
2017-04-10 20:29:33 +02:00
}
2016-08-05 18:04:08 +02:00
}