Project

General

Profile

1
import {Injectable} from "@angular/core";
2
import {HttpClient} from "@angular/common/http";
3
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
4

    
5
import {UserNotificationsRights} from './userNotificationsRights';
6
import {CustomOptions} from '../../openaireLibrary/services/servicesUtils/customOptions.class';
7
import {map} from "rxjs/operators";
8

    
9
@Injectable()
10
export class ManageUserNotificationsService {
11

    
12
    constructor(private http: HttpClient) {
13
    }
14

    
15
    getUserNotifications(properties: EnvProperties, pid: string) {
16
      let url: string = properties.adminToolsAPIURL +  properties.adminToolsPortalType + '/'+ pid + '/notifications';
17
        return this.http.get<UserNotificationsRights>(url, CustomOptions.registryOptions());
18
    }
19

    
20
    updateUserNotifications(properties: EnvProperties, pid: string, userNotificationsRights: any) {
21
        //let headers = new Headers({'Content-Type': 'application/json'});
22
        //let options = new RequestOptions({headers: headers});
23
        let body = JSON.stringify(userNotificationsRights);
24
        let url: string = properties.adminToolsAPIURL +  properties.adminToolsPortalType + '/' + pid + '/notifications';
25
        return this.http.post(url, body, CustomOptions.registryOptions());
26
                        //.do(request => console.log("Insert Response:"+request.status));
27
    }
28

    
29
    parseUserNotifications(data:any, email:string): UserNotificationsRights {
30

    
31
        var notificationRights: UserNotificationsRights = new UserNotificationsRights();
32

    
33
        for (let i = 0; i < data.length; i++) {
34
            if (email == data[i].managerEmail) {
35
                notificationRights['notifyForNewManagers'] = data[i].notifyForNewManagers;
36
                notificationRights['notifyForNewSubscribers'] = data[i].notifyForNewSubscribers;
37
                notificationRights['managerEmail'] = data[i].managerEmail;
38
            }
39
        }
40
        return notificationRights;
41
    }
42
  }
(5-5/6)