2017-12-19 13:53:46 +01:00
|
|
|
import {Injectable} from '@angular/core';
|
2020-11-11 15:43:13 +01:00
|
|
|
import {HttpClient, HttpErrorResponse} from "@angular/common/http";
|
2019-06-03 15:20:36 +02:00
|
|
|
import {throwError} from 'rxjs';
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-11-08 14:49:40 +01:00
|
|
|
import { CustomOptions } from '../../services/servicesUtils/customOptions.class';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {catchError} from "rxjs/operators";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ClaimsByTokenService {
|
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
constructor(private http: HttpClient ) {}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-09-24 12:01:05 +02:00
|
|
|
getClaims(openaireId: string, apiURL:string):any {
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-09-24 12:01:05 +02:00
|
|
|
//let url = apiURL+"project/claims?projectToken="+token;
|
|
|
|
let url = apiURL+"projects/"+openaireId+"/all_claims";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
let key = url;
|
|
|
|
|
2023-08-03 11:45:39 +02:00
|
|
|
return this.http.get(url, CustomOptions.getAuthOptionsWithBody());
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
updateClaimsCuration( selectedRight: Set<string>, selectedWrong: Set<string>, apiURL:string) {
|
|
|
|
let url = apiURL + "curate/bulk";
|
2017-12-19 13:53:46 +01:00
|
|
|
let claimsCurationInfo: any = []; //e.g.: [{"id":"2","approved":true},{"id":"1","approved":true}]
|
|
|
|
|
|
|
|
selectedRight.forEach(function(selected) {
|
2018-06-29 15:24:49 +02:00
|
|
|
//console.info(selected);
|
2017-12-19 13:53:46 +01:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let body = JSON.stringify( claimsCurationInfo );
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.warn('Json body: : '+body);
|
2019-06-03 15:20:36 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody())
|
2019-06-03 15:20:36 +02:00
|
|
|
//.map(res => res.json())
|
2019-02-14 11:15:44 +01:00
|
|
|
//.do(request => console.info("Insert Response:"+request.status) )
|
2019-06-03 15:20:36 +02:00
|
|
|
.pipe(catchError(this.handleError));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2018-06-29 15:24:49 +02:00
|
|
|
|
|
|
|
updateClaimCuration( claimCurationInfo: {"id": string, "approved": boolean}, apiURL:string) {
|
|
|
|
let url = apiURL + "curate/bulk";
|
|
|
|
let claimsCurationInfo: any = []; //e.g.: [{"id":"2","approved":true},{"id":"1","approved":true}]
|
|
|
|
claimsCurationInfo.push(claimCurationInfo);
|
|
|
|
|
|
|
|
|
|
|
|
let body = JSON.stringify( claimsCurationInfo );
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.warn('Json body: : '+body);
|
2019-06-03 15:20:36 +02:00
|
|
|
|
2018-06-29 15:24:49 +02:00
|
|
|
return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody())
|
2019-06-03 15:20:36 +02:00
|
|
|
//.map(res => res.json())
|
|
|
|
.pipe(catchError(this.handleError));
|
2018-06-29 15:24:49 +02:00
|
|
|
}
|
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
private handleError (error: HttpErrorResponse) {
|
2017-12-19 13:53:46 +01:00
|
|
|
// 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);
|
2019-06-03 15:20:36 +02:00
|
|
|
return throwError(error || 'Server error');
|
|
|
|
//return Observable.throw(error || 'Server error');
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|