1 |
61381
|
k.triantaf
|
import {Injectable} from '@angular/core';
|
2 |
|
|
import {HttpClient, HttpErrorResponse} from "@angular/common/http";
|
3 |
|
|
import {throwError} from 'rxjs';
|
4 |
|
|
import { CustomOptions } from '../../services/servicesUtils/customOptions.class';
|
5 |
|
|
|
6 |
|
|
@Injectable()
|
7 |
|
|
export class MailPrefsService {
|
8 |
|
|
constructor(private http: HttpClient ) {}
|
9 |
|
|
|
10 |
|
|
getUserEmailPreferencesForCommunity (communityId:string, apiUrl:string):any {
|
11 |
|
|
let url = apiUrl +"users/notification"+"?communityId="+communityId;
|
12 |
|
|
|
13 |
|
|
return this.http.get(url, CustomOptions.getAuthOptions())
|
14 |
|
|
//.map(request => <any> request.json())
|
15 |
|
|
//.do(request => console.info("Get user email preferences for communityId= "+communityId ));
|
16 |
|
|
//.catch(this.handleError);
|
17 |
|
|
}
|
18 |
|
|
|
19 |
|
|
getUserEmailPreferencesForOpenaire (apiUrl:string):any {
|
20 |
|
|
let url = apiUrl +"users/notification";
|
21 |
|
|
|
22 |
|
|
//var error: HttpErrorResponse = new HttpErrorResponse({"error": {"code": 204}, "status" : 204}); // doesn't work
|
23 |
|
|
//var response: Response = new Response({"body" : {"code":200, "data": []}, "status": 200, "headers": null, "url": "", "merge": null});
|
24 |
|
|
|
25 |
|
|
return this.http.get(url, CustomOptions.getAuthOptions())
|
26 |
|
|
//.timeoutWith(100, Observable.throw(response)) // goes to error
|
27 |
|
|
//.timeoutWith(100, Observable.of(response)) // goes to
|
28 |
|
|
//.do(request => console.info(request))
|
29 |
|
|
//.map(request => <any> request.json())
|
30 |
|
|
//.do(request => console.info("Get user email preferences for OpenAIRE" ));
|
31 |
|
|
//.catch(this.handleError);
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
saveUserEmailPreferences (notification: any, apiUrl: string) {
|
35 |
|
|
let url = apiUrl +"users/notification/save";
|
36 |
|
|
|
37 |
|
|
let body = JSON.stringify( notification );
|
38 |
|
|
//console.warn('Json body: : '+body);
|
39 |
|
|
//let headers = new Headers({ 'Content-Type': 'application/json' });
|
40 |
|
|
//let options = new RequestOptions({ headers: headers });
|
41 |
|
|
return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody())
|
42 |
|
|
//.map(res => res.json())
|
43 |
|
|
//.do(request => console.info("Insert Response:"+request.status) );
|
44 |
|
|
//.catch(this.handleError);
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
private handleError (error: HttpErrorResponse) {
|
48 |
|
|
// in a real world app, we may send the error to some remote logging infrastructure
|
49 |
|
|
// instead of just logging it to the console
|
50 |
|
|
console.log(error);
|
51 |
|
|
return throwError(error || 'Server error');
|
52 |
|
|
}
|
53 |
|
|
}
|