openaire-library/services/user-registry.service.ts

46 lines
2.1 KiB
TypeScript
Raw Normal View History

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 getSubscribersCount(type: string, id: string): Observable<any> {
return this.http.get(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/subscribers/count');
}
public subscribeTo(type: string, id: string): Observable<any> {
return this.http.post(properties.registryUrl + 'subscribe/' + encodeURIComponent(type) + '/' + encodeURIComponent(id),
null, CustomOptions.registryOptions())
}
public unsubscribeFrom(type: string, id: string): Observable<any> {
return this.http.post(properties.registryUrl + 'unsubscribe/' + encodeURIComponent(type) + '/' + encodeURIComponent(id),
null, CustomOptions.registryOptions())
}
public getSubscribers(type: string, id: string): Observable<any[]> {
return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/subscribers/').pipe(map(response => response.response));
}
public getManagers(type: string, id: string): Observable<any[]> {
return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/managers/').pipe(map(response => response.response));
}
public getSubscribersEmail(type: string, id: string): Observable<any[]> {
return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/subscribers/email').pipe(map(response => response.response));
}
public getManagersEmail(type: string, id: string): Observable<any[]> {
return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/managers/email').pipe(map(response => response.response));
}
}