Project

General

Profile

1
import {Injectable} from '@angular/core';
2
import {Observable} from 'rxjs/Observable';
3
import {CustomOptions} from './servicesUtils/customOptions.class';
4
import {HttpClient, HttpHeaders} from '@angular/common/http';
5
import {COOKIE} from '../login/utils/helper.class';
6

    
7
@Injectable()
8
export class CuratorPhotoService {
9
    constructor(private http: HttpClient) {
10
    }
11

    
12
    uploadPhoto(url: string, photo: File): Observable<any> {
13
        const formData = new FormData();
14
        formData.append('photo', photo);
15
        return this.http.post(url, formData, this.getAuthOptions());
16
    }
17

    
18
    deletePhoto(url: string) {
19
        return this.http.delete(url, this.getAuthOptions());
20
    }
21

    
22
    // TODO remove and use CustomOptions.getAuthOptions(false)
23
    private getAuthOptions(): any {
24
        const httpOptions = {
25
            headers: new HttpHeaders({
26
                'X-XSRF-TOKEN': COOKIE.getCookie(COOKIE.cookieName_id),
27
            })
28
        };
29
        return httpOptions;
30
    }
31
}
(1-1/23)