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 createRole(type: string, id: string, role): Observable<any[]> {
|
17
|
return this.http.post<any>(properties.registryUrl + 'createRole', role,
|
18
|
CustomOptions.registryOptions()).pipe(map((response: any) => response.response));
|
19
|
}
|
20
|
|
21
|
public getMembersCount(type: string, id: string): Observable<any> {
|
22
|
return this.http.get(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/members/count');
|
23
|
}
|
24
|
|
25
|
public subscribeTo(type: string, id: string): Observable<any> {
|
26
|
return this.http.post(properties.registryUrl + 'subscribe/' + encodeURIComponent(type) + '/' + encodeURIComponent(id),
|
27
|
null, CustomOptions.registryOptions());
|
28
|
}
|
29
|
|
30
|
public unsubscribeFrom(type: string, id: string): Observable<any> {
|
31
|
return this.http.post(properties.registryUrl + 'unsubscribe/' + encodeURIComponent(type) + '/' + encodeURIComponent(id),
|
32
|
null, CustomOptions.registryOptions());
|
33
|
}
|
34
|
|
35
|
public remove(type: string, id: string, email: string, role: "member" | "manager" = "manager"): Observable<any> {
|
36
|
return this.http.delete<any>(properties.registryUrl +
|
37
|
encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/' + role + '/' + encodeURIComponent(email), CustomOptions.registryOptions());
|
38
|
}
|
39
|
|
40
|
public invite(type: string, id: string, details: any, role: "member" | "manager" = "manager"): Observable<any[]> {
|
41
|
return this.http.post<any>(properties.registryUrl + 'invite/' +
|
42
|
encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/' + role, details,
|
43
|
CustomOptions.registryOptions()).pipe(map((response: any) => response.response));
|
44
|
}
|
45
|
|
46
|
public verify(id: string, code: string, role: "member" | "manager" = "manager"): Observable<any> {
|
47
|
return this.http.post<any>(properties.registryUrl + 'verification/' + role + '/' + encodeURIComponent(id), code, CustomOptions.registryOptions());
|
48
|
}
|
49
|
|
50
|
public getInvitation(id: string): Observable<any> {
|
51
|
return this.http.get<any>(properties.registryUrl + 'verification/' + encodeURIComponent(id), CustomOptions.registryOptions())
|
52
|
.pipe(map((response: any) => response.response));
|
53
|
}
|
54
|
|
55
|
public deleteVerification(id: string): Observable<any> {
|
56
|
return this.http.delete<any>(properties.registryUrl + 'verification/' + encodeURIComponent(id), CustomOptions.registryOptions());
|
57
|
}
|
58
|
|
59
|
public getActiveEmail(type: string, id: string, role: "member" | "manager" = "manager"): Observable<any[]> {
|
60
|
return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + "/" + role + 's/email',
|
61
|
CustomOptions.registryOptions()).pipe(map((response:any) => response.response));
|
62
|
}
|
63
|
|
64
|
public getActiveNames(type: string, id: string, role: "member" | "manager" = "manager"): Observable<any[]> {
|
65
|
return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + "/" + role + 's/',
|
66
|
CustomOptions.registryOptions()).pipe(map((response:any) => response.response));
|
67
|
}
|
68
|
|
69
|
public getPending(type: string, id: string, role: "member" | "manager" = "manager"): Observable<any[]> {
|
70
|
return this.http.get<any>(properties.registryUrl + 'invite/' + encodeURIComponent(type) + '/' + encodeURIComponent(id) + "/" + role + 's/',
|
71
|
CustomOptions.registryOptions()).pipe(map((response: any) => response.response));
|
72
|
}
|
73
|
|
74
|
public cancelInvitation(type: string, id: string, email: string, role: "member" | "manager" = "manager"): Observable<any> {
|
75
|
return this.http.delete<any>(properties.registryUrl + 'invite/' +
|
76
|
encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/' + role + '/' + encodeURIComponent(email),
|
77
|
CustomOptions.registryOptions());
|
78
|
}
|
79
|
}
|