connect-admin/src/app/services/manageProjects.service.ts

62 lines
2.1 KiB
TypeScript
Raw Normal View History

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 ManageCommunityProjectsService {
constructor(private http: Http ) {}
removeProject (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+"/projects";
return this.http.delete(url, options)
}
addProject(properties:EnvProperties, communityId: string, project: any) {
let headers = new Headers({'Content-Type': 'application/json'});
let options = new RequestOptions({headers: headers});
let url = properties.communityAPI+communityId+"/projects";
let communityProject = this.convertSearchProjectToCommunityProject(project, communityId);
let testProject: any = {
"acronym": "test",
"communityId": "egi",
"funder": "test",
"grantId": "test",
"name": "test",
"openaireId": "test"
};
return this.http.post(url, JSON.stringify(communityProject), options)
.map(res => <any> res.json())
}
convertSearchProjectToCommunityProject(project: any, community: string) : any {
let communityProject = {
"acronym": "",
"communityId": community,
"funder": "",
"grantId": "",
"name": "",
"openaireId": ""
}
communityProject.acronym = project.acronym;
communityProject.name = project.title.name;
communityProject.funder = project.funderShortname;
communityProject.grantId = project.code;
communityProject.openaireId = project.id;
return communityProject;
}
}