diff --git a/connect/communityGuard/connectSubscriber.guard.ts b/connect/communityGuard/connectSubscriber.guard.ts index b32a0153..7b2d2f66 100644 --- a/connect/communityGuard/connectSubscriber.guard.ts +++ b/connect/communityGuard/connectSubscriber.guard.ts @@ -31,7 +31,7 @@ export class ConnectSubscriberGuard implements CanActivate { if(communityDomain) { community = communityDomain; } - return this.subscribeService.isSubscribedToCommunity(properties, community, email) + return this.subscribeService.isSubscribedToCommunity(properties, community) } else { return of(false); } diff --git a/utils/subscribe/subscribe.service.ts b/utils/subscribe/subscribe.service.ts index a5b30683..adfb30f8 100644 --- a/utils/subscribe/subscribe.service.ts +++ b/utils/subscribe/subscribe.service.ts @@ -3,6 +3,7 @@ import {HttpClient} from '@angular/common/http'; import {map} from "rxjs/operators"; import {CustomOptions} from "../../services/servicesUtils/customOptions.class"; import {EnvProperties} from "../properties/env-properties"; +import {COOKIE} from "../../login/utils/helper.class"; @Injectable() export class SubscribeService { @@ -15,32 +16,45 @@ export class SubscribeService { return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url); } - 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) + getNumberOfCommunitySubscribers(properties: EnvProperties, pid: string) { + let url = properties.adminToolsAPIURL + "/community/" + pid + "/subscribers/count"; + return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url); + } + + isSubscribedToCommunity(properties: EnvProperties, pid: string) { + let url = properties.adminToolsAPIURL + "/community/" + pid + "/is-subscriber/"; + return this.http.post(url, {}, CustomOptions.getAuthOptionsWithBody()) .pipe(map(res => { - if (res['status'] && res['status'] != 200) { - return null; - } - if (res['subscribers'] && res['subscribers'] != null) { - - for (var i = 0; i < res['subscribers'].length; i++) { - if (res['subscribers'][i] != null && res['subscribers'][i].email == email) { - return true; - } - } - } - return false; - + // if (res['status'] && res['status'] != 200) { + // return null; + // } + // if (res['subscribers'] && res['subscribers'] != null) { + // + // for (var i = 0; i < res['subscribers'].length; i++) { + // if (res['subscribers'][i] != null && res['subscribers'][i].email == email) { + // return true; + // } + // } + // } + // return false; + return res; })); } - subscribeToCommunity(properties: EnvProperties, pid: string, email: string) { + subscribeToCommunity(properties: EnvProperties, pid: string) { + return this.http.post(properties.adminToolsAPIURL + "/community/" + pid + "/subscriber", {}, CustomOptions.getAuthOptionsWithBody()); + } + + unSubscribeToCommunity(properties: EnvProperties, pid: string) { + return this.http.post(properties.adminToolsAPIURL + "/community/" + pid + "/subscriber/delete", {}, CustomOptions.getAuthOptionsWithBody()); + } + + subscribeToCommunityByEmail(properties: EnvProperties, pid: string, email: string) { let subscriber = {"email": email}; return this.http.post(properties.adminToolsAPIURL + "/community/" + pid + "/subscribers", JSON.stringify(subscriber), CustomOptions.getAuthOptionsWithBody()); } - unSubscribeToCommunity(properties: EnvProperties, pid: string, email: string) { + unSubscribeToCommunityByEmail(properties: EnvProperties, pid: string, email: string) { return this.http.post(properties.adminToolsAPIURL + "/community/" + pid + "/subscribers/delete", JSON.stringify([email]), CustomOptions.getAuthOptionsWithBody()); }