2019-06-03 16:52:33 +02:00
|
|
|
import {Injectable} from "@angular/core";
|
|
|
|
import {HttpClient} from "@angular/common/http";
|
2018-10-30 16:31:16 +01:00
|
|
|
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';
|
2019-06-03 16:52:33 +02:00
|
|
|
import {map} from "rxjs/operators";
|
2018-10-30 16:31:16 +01:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ManageUserNotificationsService {
|
|
|
|
|
2019-06-03 16:52:33 +02:00
|
|
|
constructor(private http: HttpClient) {
|
2018-10-30 16:31:16 +01:00
|
|
|
}
|
|
|
|
|
2020-04-08 13:59:20 +02:00
|
|
|
getUserNotifications(properties: EnvProperties, pid: string, email: string) {
|
|
|
|
let url: string = properties.adminToolsAPIURL + 'community/'+ pid + '/notifications';
|
2019-06-03 16:52:33 +02:00
|
|
|
return this.http.get(url)//.map(res => <any> res.json())
|
|
|
|
.pipe(map(res => this.parseUserNotifications(res, email)));
|
2018-10-30 16:31:16 +01:00
|
|
|
}
|
|
|
|
|
2020-04-08 13:59:20 +02:00
|
|
|
updateUserNotifications(properties: EnvProperties, pid: 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);
|
2020-04-08 13:59:20 +02:00
|
|
|
let url: string = properties.adminToolsAPIURL + 'community/' + pid + '/notifications';
|
2019-02-14 13:20:00 +01:00
|
|
|
return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody());
|
|
|
|
//.do(request => console.log("Insert Response:"+request.status));
|
2018-10-30 16:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|