2019-06-05 15:33:18 +02:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {HttpClient} from '@angular/common/http';
|
|
|
|
import {map} from "rxjs/operators";
|
2019-06-03 15:20:36 +02:00
|
|
|
import {CustomOptions} from "../../services/servicesUtils/customOptions.class";
|
2019-06-05 15:33:18 +02:00
|
|
|
import {EnvProperties} from "../properties/env-properties";
|
2018-07-06 12:33:16 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class SubscribeService {
|
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
constructor(private http:HttpClient) {
|
2018-07-06 12:33:16 +02:00
|
|
|
}
|
2019-06-05 15:33:18 +02:00
|
|
|
getCommunitySubscribers(properties: EnvProperties, pid:string){
|
|
|
|
let url = properties.adminToolsAPIURL+ "/community/"+pid+"/subscribers";
|
|
|
|
return this.http.get<any>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
|
2018-07-06 12:33:16 +02:00
|
|
|
}
|
|
|
|
|
2019-06-05 15:33:18 +02:00
|
|
|
isSubscribedToCommunity(properties: EnvProperties, pid:string, email:string){
|
|
|
|
let url = properties.adminToolsAPIURL + "/community/"+pid+"/subscribers";
|
|
|
|
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
|
2019-06-03 15:20:36 +02:00
|
|
|
.pipe(map(res => {
|
|
|
|
if(res['status'] && res['status'] != 200) {
|
2018-10-01 14:46:21 +02:00
|
|
|
return null;
|
|
|
|
}
|
2019-06-03 15:20:36 +02:00
|
|
|
if(res['subscribers'] && res['subscribers'] != null){
|
2018-07-06 12:33:16 +02:00
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
for(var i =0; i< res['subscribers'].length; i++ ){
|
|
|
|
if(res['subscribers'][i]!=null && res['subscribers'][i].email == email){
|
2018-07-06 12:33:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
}));
|
2018-07-06 12:33:16 +02:00
|
|
|
}
|
|
|
|
subscribeToCommunity(pid:string, email:string, url:string){
|
2019-06-05 15:33:18 +02:00
|
|
|
let subscriber = {"email":email};
|
2019-06-03 15:20:36 +02:00
|
|
|
return this.http.post<any>(url+"/community/"+pid+"/subscribers", JSON.stringify(subscriber), CustomOptions.getAuthOptionsWithBody());
|
2018-07-06 12:33:16 +02:00
|
|
|
}
|
|
|
|
unSubscribeToCommunity(pid:string, email:string, url:string){
|
2019-06-03 15:20:36 +02:00
|
|
|
return this.http.post<any>(url+"/community/"+pid+"/subscribers/delete", JSON.stringify([email]), CustomOptions.getAuthOptionsWithBody());
|
2018-07-06 12:33:16 +02:00
|
|
|
}
|
2019-06-05 15:33:18 +02:00
|
|
|
getCommunitiesSubscribedTo(properties: EnvProperties, email:string){
|
|
|
|
let url = properties.adminToolsAPIURL+"/subscriber/communities?email="+email;
|
|
|
|
return this.http.get<any>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
|
2019-04-16 16:15:28 +02:00
|
|
|
}
|
2018-07-06 12:33:16 +02:00
|
|
|
}
|