78 lines
3.0 KiB
TypeScript
78 lines
3.0 KiB
TypeScript
|
import {Injectable} from '@angular/core';
|
||
|
import {Http, Response} from '@angular/http';
|
||
|
import {Jsonp, URLSearchParams,ResponseOptions, RequestOptions, Headers} from '@angular/http';
|
||
|
import {Observable} from 'rxjs/Observable';
|
||
|
import {OpenaireProperties} from '../../utils/properties/openaireProperties';
|
||
|
import 'rxjs/add/operator/do';
|
||
|
|
||
|
import { CustomOptions } from '../claim-utils/service/customOptions.class';
|
||
|
|
||
|
@Injectable()
|
||
|
export class ClaimsByTokenService {
|
||
|
|
||
|
constructor(private http: Http ) {}
|
||
|
|
||
|
getClaims(token: string, jwtToken: string):any {
|
||
|
console.info("getClaims in service");
|
||
|
|
||
|
let url = OpenaireProperties.getClaimsAPIURL()+"project/claims?projectToken="+token;
|
||
|
|
||
|
let key = url;
|
||
|
|
||
|
return this.http.get(url, CustomOptions.getAuthOptions())
|
||
|
//.map(res => <any> res.text())
|
||
|
.map(request => <any> request.json());
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
getClaims(email: string, token: string, user_token: string):any {
|
||
|
let url = OpenaireProperties.getClaimsAPIURL(); // What else?
|
||
|
let body = JSON.stringify( {"email": email, "token": token} );
|
||
|
console.warn('Json body: : '+body);
|
||
|
let headers = new Headers({ 'Content-Type': 'application/json' });
|
||
|
let options = new RequestOptions({ headers: headers });
|
||
|
return this.http.post(url, body, options)
|
||
|
.map(res => res.json())
|
||
|
.do(request => console.info("Insert Response:"+request.status) )
|
||
|
.catch(this.handleError);
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
updateClaimsCuration( selectedRight: Set<string>, selectedWrong: Set<string>) {
|
||
|
let url = OpenaireProperties.getClaimsAPIURL() + "curate/bulk";
|
||
|
let claimsCurationInfo: any = []; //e.g.: [{"id":"2","approved":true},{"id":"1","approved":true}]
|
||
|
|
||
|
selectedRight.forEach(function(selected) {
|
||
|
console.info(selected);
|
||
|
let claimCurationInfo: {"id": string, "approved": boolean} = {"id": selected, "approved": true};
|
||
|
claimsCurationInfo.push(claimCurationInfo);
|
||
|
});
|
||
|
|
||
|
selectedWrong.forEach(function(selected) {
|
||
|
let claimCurationInfo: any = {"id": selected, "approved": false};
|
||
|
claimsCurationInfo.push(claimCurationInfo);
|
||
|
});
|
||
|
|
||
|
console.info("\n\n"+claimsCurationInfo);
|
||
|
|
||
|
|
||
|
let body = JSON.stringify( claimsCurationInfo );
|
||
|
console.warn('Json body: : '+body);
|
||
|
let headers = new Headers({ 'Content-Type': 'application/json' });
|
||
|
let options = new RequestOptions({ headers: headers });
|
||
|
return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody())
|
||
|
.map(res => res.json())
|
||
|
.do(request => console.info("Insert Response:"+request.status) )
|
||
|
.catch(this.handleError);
|
||
|
}
|
||
|
|
||
|
private handleError (error: Response) {
|
||
|
// in a real world app, we may send the error to some remote logging infrastructure
|
||
|
// instead of just logging it to the console
|
||
|
console.log(error);
|
||
|
return Observable.throw(error || 'Server error');
|
||
|
}
|
||
|
}
|