32 lines
988 B
TypeScript
32 lines
988 B
TypeScript
|
import {Injectable} from '@angular/core';
|
||
|
import {Observable} from 'rxjs/Observable';
|
||
|
import {CustomOptions} from './servicesUtils/customOptions.class';
|
||
|
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
||
|
import {COOKIE} from '../login/utils/helper.class';
|
||
|
|
||
|
@Injectable()
|
||
|
export class CuratorPhotoService {
|
||
|
constructor(private http: HttpClient) {
|
||
|
}
|
||
|
|
||
|
uploadPhoto(url: string, photo: File): Observable<any> {
|
||
|
const formData = new FormData();
|
||
|
formData.append('photo', photo);
|
||
|
return this.http.post(url, formData, this.getAuthOptions());
|
||
|
}
|
||
|
|
||
|
deletePhoto(url: string) {
|
||
|
return this.http.delete(url, this.getAuthOptions());
|
||
|
}
|
||
|
|
||
|
// TODO remove and use CustomOptions.getAuthOptions(false)
|
||
|
private getAuthOptions(): any {
|
||
|
const httpOptions = {
|
||
|
headers: new HttpHeaders({
|
||
|
'X-XSRF-TOKEN': COOKIE.getCookie(COOKIE.cookieName_id),
|
||
|
})
|
||
|
};
|
||
|
return httpOptions;
|
||
|
}
|
||
|
}
|