2017-06-16 14:32:15 +02:00
|
|
|
import { Injectable } from '@angular/core'
|
2017-09-14 11:57:49 +02:00
|
|
|
import { HttpClient } from '@angular/common/http'
|
2017-06-16 14:32:15 +02:00
|
|
|
import 'rxjs/add/operator/catch'
|
|
|
|
import 'rxjs/add/operator/map'
|
2016-08-05 18:04:08 +02:00
|
|
|
|
2017-06-16 14:32:15 +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()
|
2017-03-04 11:45:47 +01:00
|
|
|
export class UserService {
|
2017-06-16 14:32:15 +02:00
|
|
|
static BASE_USERS_URL = API_URL + '/api/v1/users/'
|
2016-08-05 18:04:08 +02:00
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
constructor (
|
2017-09-14 11:57:49 +02:00
|
|
|
private authHttp: HttpClient,
|
2016-08-23 16:54:21 +02:00
|
|
|
private restExtractor: RestExtractor
|
|
|
|
) {}
|
2016-08-05 18:04:08 +02:00
|
|
|
|
2017-06-16 14:32:15 +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
|
2017-06-16 14:32:15 +02:00
|
|
|
}
|
2016-08-05 18:04:08 +02:00
|
|
|
|
2016-08-23 16:54:21 +02:00
|
|
|
return this.authHttp.put(url, body)
|
|
|
|
.map(this.restExtractor.extractDataBool)
|
2017-09-14 11:57:49 +02:00
|
|
|
.catch(res => this.restExtractor.handleError(res))
|
2016-08-05 18:04:08 +02:00
|
|
|
}
|
2017-04-06 21:21:03 +02:00
|
|
|
|
2017-09-05 21:29:39 +02:00
|
|
|
updateMyDetails (details: UserUpdateMe) {
|
|
|
|
const url = UserService.BASE_USERS_URL + 'me'
|
2017-04-06 21:21:03 +02:00
|
|
|
|
|
|
|
return this.authHttp.put(url, details)
|
|
|
|
.map(this.restExtractor.extractDataBool)
|
2017-09-14 11:57:49 +02:00
|
|
|
.catch(res => this.restExtractor.handleError(res))
|
2017-04-06 21:21:03 +02:00
|
|
|
}
|
2017-04-10 20:29:33 +02:00
|
|
|
|
2017-07-10 19:43:21 +02:00
|
|
|
signup (userCreate: UserCreate) {
|
2017-09-14 11:57:49 +02:00
|
|
|
return this.authHttp.post(UserService.BASE_USERS_URL + 'register', userCreate)
|
2017-04-10 20:29:33 +02:00
|
|
|
.map(this.restExtractor.extractDataBool)
|
2017-09-14 11:57:49 +02:00
|
|
|
.catch(res => this.restExtractor.handleError(res))
|
2017-04-10 20:29:33 +02:00
|
|
|
}
|
2016-08-05 18:04:08 +02:00
|
|
|
}
|