Changeset View
Changeset View
Standalone View
Standalone View
src/app/_services/profile.service.ts
Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | setBio(author: Author, bio: any): Observable<Author> { | ||||
return this.httpService.PATCH('/users/', body) | return this.httpService.PATCH('/users/', body) | ||||
.map((response: Response) => { | .map((response: Response) => { | ||||
console.log('You leveled up some stats'); | console.log('You leveled up some stats'); | ||||
return Author.parse(response); | return Author.parse(response); | ||||
}).catch((err) => { | }).catch((err) => { | ||||
return Observable.of(new AuthorError( | return Observable.of(new AuthorError( | ||||
JSON.parse(err._body).non_field_errors, | err.error.non_field_errors, | ||||
JSON.parse(err._body).text | err.error.text | ||||
)); | )); | ||||
}); | }); | ||||
} | } | ||||
setEmail(email: any): Observable<Account> { | setEmail(email: any): Observable<Account> { | ||||
const body = { | const body = { | ||||
email: email | email: email | ||||
}; | }; | ||||
return this.httpService.PATCH('/account/', body) | return this.httpService.PATCH('/account/', body) | ||||
.map((response: Response) => { | .map((response: Response) => { | ||||
console.log('You have mail!'); | console.log('You have mail!'); | ||||
return Account.parse(response); | return Account.parse(response); | ||||
}).catch((err) => { | }).catch((err) => { | ||||
return Observable.of(new AccountError( | return Observable.of(new AccountError( | ||||
JSON.parse(err._body).non_field_errors, | err.error.non_field_errors, | ||||
JSON.parse(err._body).text | err.error.text | ||||
)); | )); | ||||
}); | }); | ||||
} | } | ||||
setPassword(password: any): Observable<Account> { | setPassword(password: any): Observable<Account> { | ||||
const body = { | const body = { | ||||
password: password | password: password | ||||
}; | }; | ||||
return this.httpService.PATCH('/account/', body) | return this.httpService.PATCH('/account/', body) | ||||
.map((response: Response) => { | .map((response: Response) => { | ||||
console.log('You have been securely encryptified'); | console.log('You have been securely encryptified'); | ||||
return Account.parse(response); | return Account.parse(response); | ||||
}).catch((err) => { | }).catch((err) => { | ||||
return Observable.of(new AccountError( | return Observable.of(new AccountError( | ||||
JSON.parse(err._body).non_field_errors, | err.error.non_field_errors, | ||||
JSON.parse(err._body).text | err.error.text | ||||
)); | )); | ||||
}); | }); | ||||
} | } | ||||
setProfilePicture(image: any): Observable<Profile> { | setProfilePicture(image: any): Observable<Profile> { | ||||
const formData: FormData = new FormData(); | const formData: FormData = new FormData(); | ||||
formData.append('avatar', image, image.name); | formData.append('avatar', image, image.name); | ||||
return this.httpService.PUT_IMAGE('/users/', formData) | return this.httpService.PUT_IMAGE('/users/', formData) | ||||
.map((response: Response) => { | .map((response: Response) => { | ||||
console.log('You looked in the mirror and got frightened'); | console.log('You looked in the mirror and got frightened'); | ||||
return Profile.parse(response); | return Profile.parse(response); | ||||
}).catch((err) => { | }).catch((err) => { | ||||
return Observable.of(new ProfileError( | return Observable.of(new ProfileError( | ||||
JSON.parse(err._body).non_field_errors, | err.error.non_field_errors, | ||||
JSON.parse(err._body).text | err.error.text | ||||
)); | )); | ||||
}); | }); | ||||
} | } | ||||
} | } |