Project

General

Profile

1
import {Injectable} from '@angular/core';
2
import {HttpClient} from '@angular/common/http';
3
import {Observable} from 'rxjs';
4
import {properties} from '../../../environments/environment';
5
import {CustomOptions} from './servicesUtils/customOptions.class';
6
import {map} from 'rxjs/operators';
7

    
8
@Injectable({
9
  providedIn: 'root'
10
})
11
export class UserRegistryService {
12

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

    
16
  public getSubscribersCount(type: string, id: string): Observable<any> {
17
    return this.http.get(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/subscribers/count');
18
  }
19

    
20
  public subscribeTo(type: string, id: string): Observable<any> {
21
    return this.http.post(properties.registryUrl + 'subscribe/' + encodeURIComponent(type) + '/' + encodeURIComponent(id),
22
      null, CustomOptions.registryOptions());
23
  }
24

    
25
  public unsubscribeFrom(type: string, id: string): Observable<any> {
26
    return this.http.post(properties.registryUrl + 'unsubscribe/' + encodeURIComponent(type) + '/' + encodeURIComponent(id),
27
      null, CustomOptions.registryOptions());
28
  }
29

    
30
  public removeManagerRole(type: string, id: string, email: string): Observable<any> {
31
    return this.http.delete<any>(properties.registryUrl +
32
      encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/manager/' + encodeURIComponent(email), CustomOptions.registryOptions());
33
  }
34

    
35
  public invite(type: string, id: string, email: string, details: any): Observable<any[]> {
36
    return this.http.post<any>(properties.registryUrl + 'invite/' +
37
      encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/manager/' + encodeURIComponent(email), details,
38
      CustomOptions.registryOptions()).pipe(map((response: any) => response.response));
39
  }
40

    
41
  public cancelInvitation(type: string, id: string, email: string): Observable<any> {
42
    return this.http.delete<any>(properties.registryUrl + 'invite/' +
43
      encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/manager/' + encodeURIComponent(email),
44
      CustomOptions.registryOptions());
45
  }
46

    
47
  public getPendingManagers(type: string, id: string): Observable<any[]> {
48
    return this.http.get<any>(properties.registryUrl + 'invite/' + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/managers/',
49
      CustomOptions.registryOptions()).pipe(map((response: any) => response.response));
50
  }
51

    
52
  public getSubscribers(type: string, id: string): Observable<any[]> {
53
    return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/subscribers/').pipe(map(response => response.response));
54
  }
55

    
56
  public getManagers(type: string, id: string): Observable<any[]> {
57
    return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/managers/').pipe(map(response => response.response));
58
  }
59

    
60
  public getSubscribersEmail(type: string, id: string): Observable<any[]> {
61
    return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/subscribers/email').pipe(map(response => response.response));
62
  }
63

    
64
  public getInvitation(id: string): Observable<any> {
65
    return this.http.get<any>(properties.registryUrl + 'verification/' + encodeURIComponent(id), CustomOptions.registryOptions())
66
      .pipe(map((response: any) => response.response));
67
  }
68

    
69
  public verify(id: string, code: string): Observable<any> {
70
    return this.http.post<any>(properties.registryUrl + 'verification/' + encodeURIComponent(id), code, CustomOptions.registryOptions());
71
  }
72

    
73
  public deleteVerification(id: string): Observable<any> {
74
    return this.http.delete<any>(properties.registryUrl + 'verification/' + encodeURIComponent(id), CustomOptions.registryOptions());
75
  }
76

    
77
  public getManagersEmail(type: string, id: string): Observable<any[]> {
78
    return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/managers/email').pipe(map(response => response.response));
79
  }
80
}
(21-21/22)