2018-10-30 16:31:16 +01:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {Http, Response, Headers, RequestOptions} from '@angular/http';
|
|
|
|
|
|
|
|
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
|
|
|
|
|
|
|
import {UserNotificationsRights} from './userNotificationsRights';
|
2018-11-23 15:37:15 +01:00
|
|
|
import {CustomOptions} from '../../openaireLibrary/services/servicesUtils/customOptions.class';
|
2018-10-30 16:31:16 +01:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ManageUserNotificationsService {
|
|
|
|
|
|
|
|
constructor(private http: Http) {
|
|
|
|
}
|
|
|
|
|
|
|
|
getUserNotifications(url: string, email: string) {
|
|
|
|
return this.http.get(url).map(res => <any> res.json())
|
|
|
|
.map(res => this.parseUserNotifications(res, email));
|
|
|
|
}
|
|
|
|
|
|
|
|
updateUserNotifications(url: string, userNotificationsRights: any) {
|
2019-01-16 12:29:26 +01:00
|
|
|
//let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
//let options = new RequestOptions({headers: headers});
|
2018-10-30 16:31:16 +01:00
|
|
|
let body = JSON.stringify(userNotificationsRights);
|
|
|
|
|
|
|
|
console.log(body);
|
|
|
|
|
2018-11-23 15:37:15 +01:00
|
|
|
return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody())
|
2018-10-30 16:31:16 +01:00
|
|
|
.do(request => console.log("Insert Response:"+request.status));
|
|
|
|
}
|
|
|
|
|
|
|
|
parseUserNotifications(data:any, email:string): UserNotificationsRights {
|
|
|
|
|
|
|
|
var notificationRights: UserNotificationsRights = new UserNotificationsRights();
|
|
|
|
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
if (email == data[i].managerEmail) {
|
|
|
|
notificationRights['notifyForNewManagers'] = data[i].notifyForNewManagers;
|
|
|
|
notificationRights['notifyForNewSubscribers'] = data[i].notifyForNewSubscribers;
|
|
|
|
notificationRights['managerEmail'] = data[i].managerEmail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return notificationRights;
|
|
|
|
}
|
|
|
|
}
|