50 lines
2.0 KiB
TypeScript
50 lines
2.0 KiB
TypeScript
|
import {Injectable} from '@angular/core';
|
||
|
import {Http, Response, Headers, RequestOptions} from '@angular/http';
|
||
|
import {Observable} from 'rxjs/Observable';
|
||
|
import{EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
||
|
|
||
|
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
|
||
|
import { ErrorObservable } from 'rxjs/observable/ErrorObservable';
|
||
|
import { catchError } from 'rxjs/operators';
|
||
|
|
||
|
@Injectable()
|
||
|
export class ManageCommunityContentProvidersService {
|
||
|
constructor(private http: Http ) {}
|
||
|
|
||
|
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 url = properties.communityAPI+communityId+"/contentproviders";
|
||
|
return this.http.delete(url, options)
|
||
|
}
|
||
|
|
||
|
addContentProvider(properties:EnvProperties, communityId: string, contentProvider: any) {
|
||
|
let headers = new Headers({'Content-Type': 'application/json'});
|
||
|
let options = new RequestOptions({headers: headers});
|
||
|
|
||
|
let url = properties.communityAPI+communityId+"/contentproviders";
|
||
|
|
||
|
let communityContentProvider = this.convertSearchContentProviderToCommunityContentProvider(contentProvider, communityId);
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
}
|