diff options
| author | Kamen Mladenov <kamen.d.mladenov@protonmail.com> | 2021-04-09 19:55:59 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-09 19:55:59 +0300 |
| commit | f849e37ccdd6fd48f83119a3b3b65cdd8b765dc3 (patch) | |
| tree | 83b88a773bb7dc053bb3aced35bce302264ec925 /src/app/services/profile-picture.service.ts | |
| parent | bcd88af53b1a920d728ec98b45daa9ac2e2c0917 (diff) | |
| parent | c13889759d70687de6833c505221c203f65fedb8 (diff) | |
| download | DevHive-Angular-f849e37ccdd6fd48f83119a3b3b65cdd8b765dc3.tar DevHive-Angular-f849e37ccdd6fd48f83119a3b3b65cdd8b765dc3.tar.gz DevHive-Angular-f849e37ccdd6fd48f83119a3b3b65cdd8b765dc3.zip | |
Second Stage: Complete
Diffstat (limited to 'src/app/services/profile-picture.service.ts')
| -rw-r--r-- | src/app/services/profile-picture.service.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/app/services/profile-picture.service.ts b/src/app/services/profile-picture.service.ts new file mode 100644 index 0000000..8b9d0a3 --- /dev/null +++ b/src/app/services/profile-picture.service.ts @@ -0,0 +1,32 @@ +import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { Guid } from 'guid-typescript'; +import { Observable } from 'rxjs'; +import { AppConstants } from '../app-constants.module'; +import { TokenService } from './token.service'; + +@Injectable({ + providedIn: 'root' +}) +export class ProfilePictureService { + constructor(private _http: HttpClient, private _tokenService: TokenService) + { } + + putPictureWithSessionStorageRequest(newPicture: File): Observable<object> { + const userId = this._tokenService.getUserIdFromSessionStorageToken(); + const token = this._tokenService.getTokenFromSessionStorage(); + + return this.putRatingRequest(userId, token, newPicture); + } + + putRatingRequest(userId: Guid, authToken: string, newPicture: File): Observable<object> { + const options = { + params: new HttpParams().set('UserId', userId.toString()), + headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) + }; + const form = new FormData(); + form.append('picture', newPicture); + + return this._http.put(AppConstants.API_PROFILE_PICTURE_URL, form, options); + } +} |
