import {Injectable} from '@angular/core'; import {HttpClient} from '@angular/common/http'; import {Observable} from 'rxjs'; import {properties} from '../../../environments/environment'; import {CustomOptions} from './servicesUtils/customOptions.class'; import {map} from 'rxjs/operators'; @Injectable({ providedIn: 'root' }) export class UserRegistryService { constructor(private http: HttpClient) { } public createRole(type: string, id: string, role): Observable { return this.http.post(properties.registryUrl + 'createRole', role, CustomOptions.registryOptions()).pipe(map((response: any) => response.response)); } public getSubscribersCount(type: string, id: string): Observable { return this.http.get(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/subscribers/count'); } public subscribeTo(type: string, id: string): Observable { return this.http.post(properties.registryUrl + 'subscribe/' + encodeURIComponent(type) + '/' + encodeURIComponent(id), null, CustomOptions.registryOptions()); } public unsubscribeFrom(type: string, id: string): Observable { return this.http.post(properties.registryUrl + 'unsubscribe/' + encodeURIComponent(type) + '/' + encodeURIComponent(id), null, CustomOptions.registryOptions()); } public remove(type: string, id: string, email: string, role: "member" | "manager" = "manager"): Observable { return this.http.delete(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/' + role + '/' + encodeURIComponent(email), CustomOptions.registryOptions()); } public invite(type: string, id: string, email: string, details: any, role: "member" | "manager" = "manager"): Observable { return this.http.post(properties.registryUrl + 'invite/' + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/' + role + '/' + encodeURIComponent(email), details, CustomOptions.registryOptions()).pipe(map((response: any) => response.response)); } public verify(id: string, code: string, role: "member" | "manager" = "manager"): Observable { return this.http.post(properties.registryUrl + 'verification/' + role + '/' + encodeURIComponent(id), code, CustomOptions.registryOptions()); } public getInvitation(id: string): Observable { return this.http.get(properties.registryUrl + 'verification/' + encodeURIComponent(id), CustomOptions.registryOptions()) .pipe(map((response: any) => response.response)); } public deleteVerification(id: string): Observable { return this.http.delete(properties.registryUrl + 'verification/' + encodeURIComponent(id), CustomOptions.registryOptions()); } public getActiveEmail(type: string, id: string, role: "member" | "manager" = "manager"): Observable { return this.http.get(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + "/" + role + 's/email', CustomOptions.registryOptions()).pipe(map((response:any) => response.response)); } public getActiveNames(type: string, id: string, role: "member" | "manager" = "manager"): Observable { return this.http.get(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + "/" + role + 's/', CustomOptions.registryOptions()).pipe(map((response:any) => response.response)); } public getPending(type: string, id: string, role: "member" | "manager" = "manager"): Observable { return this.http.get(properties.registryUrl + 'invite/' + encodeURIComponent(type) + '/' + encodeURIComponent(id) + "/" + role + 's/', CustomOptions.registryOptions()).pipe(map((response: any) => response.response)); } public cancelInvitation(type: string, id: string, email: string, role: "member" | "manager" = "manager"): Observable { return this.http.delete(properties.registryUrl + 'invite/' + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/' + role + '/' + encodeURIComponent(email), CustomOptions.registryOptions()); } }