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

109 lines
5.5 KiB
TypeScript

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 removeManager(type: string, id: string, email: string): Observable<any> {
return this.http.delete<any>(properties.registryUrl +
encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/manager/' + encodeURIComponent(email), CustomOptions.registryOptions());
}
public removeMember(type: string, id: string, email: string): Observable<any> {
return this.http.delete<any>(properties.registryUrl +
encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/member/' + encodeURIComponent(email), CustomOptions.registryOptions());
}
public inviteManager(type: string, id: string, email: string, details: any): Observable<any[]> {
return this.http.post<any>(properties.registryUrl + 'invite/' +
encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/manager/' + encodeURIComponent(email), details,
CustomOptions.registryOptions()).pipe(map((response: any) => response.response));
}
public inviteMember(type: string, id: string, email: string, details: any): Observable<any[]> {
return this.http.post<any>(properties.registryUrl + 'invite/' +
encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/member/' + encodeURIComponent(email), details,
CustomOptions.registryOptions()).pipe(map((response: any) => response.response));
}
public cancelManagerInvitation(type: string, id: string, email: string): Observable<any> {
return this.http.delete<any>(properties.registryUrl + 'invite/' +
encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/manager/' + encodeURIComponent(email),
CustomOptions.registryOptions());
}
public cancelMemberInvitation(type: string, id: string, email: string): Observable<any> {
return this.http.delete<any>(properties.registryUrl + 'invite/' +
encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/member/' + encodeURIComponent(email),
CustomOptions.registryOptions());
}
public getPendingManagers(type: string, id: string): Observable<any[]> {
return this.http.get<any>(properties.registryUrl + 'invite/' + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/managers/',
CustomOptions.registryOptions()).pipe(map((response: any) => response.response));
}
public getPendingMembers(type: string, id: string): Observable<any[]> {
return this.http.get<any>(properties.registryUrl + 'invite/' + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/members/',
CustomOptions.registryOptions()).pipe(map((response: any) => response.response));
}
public getMembers(type: string, id: string): Observable<any[]> {
return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/members/',
CustomOptions.registryOptions()).pipe(map((response:any) => 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 getMembersEmail(type: string, id: string): Observable<any[]> {
return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/members/email',
CustomOptions.registryOptions()).pipe(map((response:any) => response.response));
}
public getInvitation(id: string): Observable<any> {
return this.http.get<any>(properties.registryUrl + 'verification/' + encodeURIComponent(id), CustomOptions.registryOptions())
.pipe(map((response: any) => response.response));
}
public verifyManager(id: string, code: string): Observable<any> {
return this.http.post<any>(properties.registryUrl + 'verification/manager/' + encodeURIComponent(id), code, CustomOptions.registryOptions());
}
public verifyMember(id: string, code: string): Observable<any> {
return this.http.post<any>(properties.registryUrl + 'verification/member/' + encodeURIComponent(id), code, CustomOptions.registryOptions());
}
public deleteVerification(id: string): Observable<any> {
return this.http.delete<any>(properties.registryUrl + 'verification/' + encodeURIComponent(id), CustomOptions.registryOptions());
}
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));
}
}