51 lines
2.1 KiB
TypeScript
51 lines
2.1 KiB
TypeScript
import {Injectable} from '@angular/core';
|
|
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
|
import{EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
|
|
|
@Injectable()
|
|
export class ManageCommunityContentProvidersService {
|
|
constructor(private http: HttpClient ) {}
|
|
|
|
removeContentProvider (properties:EnvProperties, communityId: string, id: string):any {
|
|
//let headers = new Headers({'Content-Type': 'application/json', 'accept': 'application/json'});
|
|
//let options = new RequestOptions({headers: headers, body: id});
|
|
|
|
let headers = new HttpHeaders({'Content-Type': 'application/json', 'accept': 'application/json'});
|
|
|
|
let url = properties.communityAPI+communityId+"/contentproviders";
|
|
//return this.http.delete(url, options)
|
|
return this.http.request('delete', url, { body: id, headers: headers})
|
|
}
|
|
|
|
addContentProvider(properties:EnvProperties, communityId: string, contentProvider: any) {
|
|
//let headers = new Headers({'Content-Type': 'application/json'});
|
|
//let options = new RequestOptions({headers: headers});
|
|
|
|
let headers = new HttpHeaders({'Content-Type': 'application/json'});
|
|
|
|
let url = properties.communityAPI+communityId+"/contentproviders";
|
|
|
|
let communityContentProvider = this.convertSearchContentProviderToCommunityContentProvider(contentProvider, communityId);
|
|
|
|
return this.http.post<any>(url, JSON.stringify(communityContentProvider), {headers: headers});
|
|
//return this.http.post(url, JSON.stringify(communityContentProvider), options)
|
|
//.map(res => <any> res.json())
|
|
}
|
|
|
|
convertSearchContentProviderToCommunityContentProvider(contentProvider: any, community: string) : any {
|
|
let communityContentProvider = {
|
|
"communityId": community,
|
|
"officialname": "",
|
|
"name": "",
|
|
"openaireId": ""
|
|
}
|
|
|
|
communityContentProvider.officialname = contentProvider.title.name;
|
|
communityContentProvider.name = contentProvider.englishname;
|
|
communityContentProvider.openaireId = contentProvider.id;
|
|
|
|
return communityContentProvider;
|
|
}
|
|
|
|
}
|