2020-08-06 13:50:08 +02:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {HttpClient} from '@angular/common/http';
|
2020-09-08 16:33:06 +02:00
|
|
|
import {Observable} from 'rxjs';
|
|
|
|
import {properties} from '../../../environments/environment';
|
|
|
|
import {CustomOptions} from './servicesUtils/customOptions.class';
|
|
|
|
import {map} from 'rxjs/operators';
|
2020-08-06 13:50:08 +02:00
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class UserRegistryService {
|
2020-09-08 16:33:06 +02:00
|
|
|
|
2020-08-06 13:50:08 +02:00
|
|
|
constructor(private http: HttpClient) {
|
|
|
|
}
|
2020-11-03 19:25:03 +01:00
|
|
|
|
|
|
|
public createRole(type: string, id: string, role): Observable<any[]> {
|
|
|
|
return this.http.post<any>(properties.registryUrl + 'createRole', role,
|
|
|
|
CustomOptions.registryOptions()).pipe(map((response: any) => response.response));
|
|
|
|
}
|
|
|
|
|
2020-08-06 13:50:08 +02:00
|
|
|
public getSubscribersCount(type: string, id: string): Observable<any> {
|
|
|
|
return this.http.get(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/subscribers/count');
|
|
|
|
}
|
2020-09-08 16:33:06 +02:00
|
|
|
|
2020-08-06 13:50:08 +02:00
|
|
|
public subscribeTo(type: string, id: string): Observable<any> {
|
|
|
|
return this.http.post(properties.registryUrl + 'subscribe/' + encodeURIComponent(type) + '/' + encodeURIComponent(id),
|
2020-09-08 16:33:06 +02:00
|
|
|
null, CustomOptions.registryOptions());
|
2020-08-06 13:50:08 +02:00
|
|
|
}
|
2020-09-08 16:33:06 +02:00
|
|
|
|
2020-08-06 13:50:08 +02:00
|
|
|
public unsubscribeFrom(type: string, id: string): Observable<any> {
|
|
|
|
return this.http.post(properties.registryUrl + 'unsubscribe/' + encodeURIComponent(type) + '/' + encodeURIComponent(id),
|
2020-09-08 16:33:06 +02:00
|
|
|
null, CustomOptions.registryOptions());
|
2020-08-06 13:50:08 +02:00
|
|
|
}
|
2020-08-31 13:33:48 +02:00
|
|
|
|
2020-11-03 19:25:03 +01:00
|
|
|
public remove(type: string, id: string, email: string, role: "member" | "manager" = "manager"): Observable<any> {
|
2020-08-31 13:33:48 +02:00
|
|
|
return this.http.delete<any>(properties.registryUrl +
|
2020-11-03 19:25:03 +01:00
|
|
|
encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/' + role + '/' + encodeURIComponent(email), CustomOptions.registryOptions());
|
2020-08-31 13:33:48 +02:00
|
|
|
}
|
2020-10-05 15:15:33 +02:00
|
|
|
|
2020-11-03 19:25:03 +01:00
|
|
|
public invite(type: string, id: string, email: string, details: any, role: "member" | "manager" = "manager"): Observable<any[]> {
|
2020-08-31 13:33:48 +02:00
|
|
|
return this.http.post<any>(properties.registryUrl + 'invite/' +
|
2020-11-03 19:25:03 +01:00
|
|
|
encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/' + role + '/' + encodeURIComponent(email), details,
|
2020-08-31 13:33:48 +02:00
|
|
|
CustomOptions.registryOptions()).pipe(map((response: any) => response.response));
|
|
|
|
}
|
2020-10-05 15:15:33 +02:00
|
|
|
|
2020-11-03 19:25:03 +01:00
|
|
|
public verify(id: string, code: string, role: "member" | "manager" = "manager"): Observable<any> {
|
|
|
|
return this.http.post<any>(properties.registryUrl + 'verification/' + role + '/' + encodeURIComponent(id), code, CustomOptions.registryOptions());
|
2020-08-31 13:33:48 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 19:25:03 +01:00
|
|
|
public getInvitation(id: string): Observable<any> {
|
|
|
|
return this.http.get<any>(properties.registryUrl + 'verification/' + encodeURIComponent(id), CustomOptions.registryOptions())
|
|
|
|
.pipe(map((response: any) => response.response));
|
2020-10-05 15:15:33 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 19:25:03 +01:00
|
|
|
public deleteVerification(id: string): Observable<any> {
|
|
|
|
return this.http.delete<any>(properties.registryUrl + 'verification/' + encodeURIComponent(id), CustomOptions.registryOptions());
|
2020-10-05 15:15:33 +02:00
|
|
|
}
|
2020-09-08 16:33:06 +02:00
|
|
|
|
2020-11-03 19:25:03 +01:00
|
|
|
public getActiveEmail(type: string, id: string, role: "member" | "manager" = "manager"): Observable<any[]> {
|
|
|
|
return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + "/" + role + 's/email',
|
2020-10-05 15:15:33 +02:00
|
|
|
CustomOptions.registryOptions()).pipe(map((response:any) => response.response));
|
2020-08-06 13:50:08 +02:00
|
|
|
}
|
2020-11-03 19:25:03 +01:00
|
|
|
|
|
|
|
public getActiveNames(type: string, id: string, role: "member" | "manager" = "manager"): Observable<any[]> {
|
|
|
|
return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + "/" + role + 's/',
|
2020-10-05 15:15:33 +02:00
|
|
|
CustomOptions.registryOptions()).pipe(map((response:any) => response.response));
|
2020-08-06 13:50:08 +02:00
|
|
|
}
|
2020-10-05 15:15:33 +02:00
|
|
|
|
2020-11-03 19:25:03 +01:00
|
|
|
public getPending(type: string, id: string, role: "member" | "manager" = "manager"): Observable<any[]> {
|
|
|
|
return this.http.get<any>(properties.registryUrl + 'invite/' + encodeURIComponent(type) + '/' + encodeURIComponent(id) + "/" + role + 's/',
|
|
|
|
CustomOptions.registryOptions()).pipe(map((response: any) => response.response));
|
2020-08-12 17:16:09 +02:00
|
|
|
}
|
2020-11-03 19:25:03 +01:00
|
|
|
|
|
|
|
public cancelInvitation(type: string, id: string, email: string, role: "member" | "manager" = "manager"): Observable<any> {
|
|
|
|
return this.http.delete<any>(properties.registryUrl + 'invite/' +
|
|
|
|
encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/' + role + '/' + encodeURIComponent(email),
|
|
|
|
CustomOptions.registryOptions());
|
2020-08-06 13:50:08 +02:00
|
|
|
}
|
|
|
|
}
|