2019-06-07 14:51:26 +02:00
|
|
|
import {Injectable} from '@angular/core';
|
2019-06-11 15:33:32 +02:00
|
|
|
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
2019-06-07 14:51:26 +02:00
|
|
|
import {BehaviorSubject, Observable} from 'rxjs';
|
|
|
|
import {Affiliation} from '../../utils/entities/CuratorInfo';
|
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class AffiliationService {
|
|
|
|
|
|
|
|
private affiliationsSubject: BehaviorSubject<Affiliation[]> = new BehaviorSubject([]);
|
|
|
|
|
|
|
|
constructor(private http: HttpClient) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public initAffiliations(properties: EnvProperties, url: string): void {
|
|
|
|
this.http.get<Affiliation[]>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url).
|
|
|
|
subscribe((affiliations) => {
|
|
|
|
this.affiliationsSubject.next(affiliations);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public get affiliations(): Observable<Affiliation[]> {
|
|
|
|
return this.affiliationsSubject.asObservable();
|
|
|
|
}
|
|
|
|
|
2019-06-11 15:33:32 +02:00
|
|
|
public updateAffiliation(url: string, affiliation: Affiliation) {
|
|
|
|
let headers = new HttpHeaders({'Content-Type': 'application/json', 'accept' : 'application/json'});
|
|
|
|
return this.http.post<Affiliation>(url, JSON.stringify(affiliation), {headers: headers});
|
|
|
|
}
|
|
|
|
|
|
|
|
public deleteAffiliation(url: string, id: string) {
|
|
|
|
let headers = new HttpHeaders({'Content-Type': 'application/json', 'accept' : 'application/json'});
|
|
|
|
return this.http.request('delete', url, { body: id, headers: headers})
|
2019-06-07 14:51:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|