2020-08-06 13:50:08 +02:00
|
|
|
import {Injectable} from '@angular/core';
|
2024-02-12 13:53:07 +01:00
|
|
|
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';
|
2023-11-30 13:20:00 +01:00
|
|
|
import {Role} from "../login/utils/helper.class";
|
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
|
|
|
|
2021-09-17 19:13:35 +02:00
|
|
|
public createRole(type: string, id: string): Observable<any[]> {
|
2023-11-30 13:20:00 +01:00
|
|
|
return this.http.post<any>(properties.registryUrl + 'create/' + Role.GROUP + type + '/' + id, null,
|
2020-11-03 19:25:03 +01:00
|
|
|
CustomOptions.registryOptions()).pipe(map((response: any) => response.response));
|
|
|
|
}
|
|
|
|
|
2021-02-19 18:50:34 +01:00
|
|
|
public getMembersCount(type: string, id: string): Observable<any> {
|
2023-02-09 15:30:24 +01:00
|
|
|
let url = properties.registryUrl + type + '/' + id + '/members/count';
|
|
|
|
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
|
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 subscribeTo(type: string, id: string): Observable<any> {
|
2023-02-09 15:30:24 +01:00
|
|
|
return this.http.post(properties.registryUrl + 'subscribe/' + type + '/' + 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> {
|
2023-02-09 15:30:24 +01:00
|
|
|
return this.http.post(properties.registryUrl + 'unsubscribe/' + type + '/' + 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 +
|
2023-11-30 13:20:00 +01:00
|
|
|
Role.GROUP + type + '/' + id + '/' + role + '/' + encodeURIComponent(email), CustomOptions.registryOptions());
|
2020-08-31 13:33:48 +02:00
|
|
|
}
|
2020-10-05 15:15:33 +02:00
|
|
|
|
2020-11-19 18:13:27 +01:00
|
|
|
public invite(type: string, id: 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/' +
|
2023-11-30 13:20:00 +01:00
|
|
|
Role.GROUP + type + '/' + id + '/' + role, 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> {
|
2023-02-09 15:30:24 +01:00
|
|
|
return this.http.post<any>(properties.registryUrl + 'verification/' + role + '/' + 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> {
|
2023-02-09 15:30:24 +01:00
|
|
|
return this.http.get<any>(properties.registryUrl + 'verification/' + id, CustomOptions.registryOptions())
|
2020-11-03 19:25:03 +01:00
|
|
|
.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> {
|
2023-02-09 15:30:24 +01:00
|
|
|
return this.http.delete<any>(properties.registryUrl + 'verification/' + id, CustomOptions.registryOptions());
|
2020-10-05 15:15:33 +02:00
|
|
|
}
|
2020-09-08 16:33:06 +02:00
|
|
|
|
2024-01-24 19:13:05 +01:00
|
|
|
public getActive(type: string, id: string, role: "member" | "manager" = "manager", admin = false): Observable<any[]> {
|
2023-11-30 13:20:00 +01:00
|
|
|
let url = properties.registryUrl + Role.GROUP + type + '/' + id + "/" + role + 's';
|
2024-01-24 19:13:05 +01:00
|
|
|
return this.http.get<any>((properties.useCache && !admin) ? (properties.cacheUrl + encodeURIComponent(url)) : url,
|
2021-09-17 19:13:35 +02:00
|
|
|
CustomOptions.registryOptions()).pipe(map((response:any) => response.response), map(users => {
|
|
|
|
if(users.length > 0 && !users[0].email) {
|
|
|
|
return [];
|
|
|
|
} else {
|
|
|
|
return users;
|
|
|
|
}
|
|
|
|
}));
|
2020-08-06 13:50:08 +02:00
|
|
|
}
|
2024-02-12 13:53:07 +01:00
|
|
|
|
2024-01-24 19:13:05 +01:00
|
|
|
public getPending(type: string, id: string, role: "member" | "manager" = "manager", admin = false): Observable<any[]> {
|
2023-11-30 13:20:00 +01:00
|
|
|
let url = properties.registryUrl + 'invite/' + Role.GROUP + type + '/' +id + "/" + role + 's/';
|
2024-01-24 19:13:05 +01:00
|
|
|
return this.http.get<any>((properties.useCache && !admin) ? (properties.cacheUrl + encodeURIComponent(url)) : url,
|
2020-11-03 19:25:03 +01:00
|
|
|
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/' +
|
2024-01-12 08:15:04 +01:00
|
|
|
Role.GROUP + type + '/' + id + '/' + role + '/' + encodeURIComponent(email),
|
2020-11-03 19:25:03 +01:00
|
|
|
CustomOptions.registryOptions());
|
2020-08-06 13:50:08 +02:00
|
|
|
}
|
|
|
|
}
|