Revision 55964
Added by Argiro Kokogiannaki almost 5 years ago
subscribe.service.ts | ||
---|---|---|
1 | 1 |
import { Injectable } from '@angular/core'; |
2 | 2 |
import { Http, Response, Headers, RequestOptions } from '@angular/http'; |
3 |
import { Observable } from 'rxjs/Rx'; |
|
3 |
import { HttpClient } from '@angular/common/http'; |
|
4 |
import { HttpHeaders } from '@angular/common/http'; |
|
5 |
import { Observable } from 'rxjs'; |
|
4 | 6 |
import {COOKIE} from "../../login/utils/helper.class" |
7 |
import { map } from "rxjs/operators"; |
|
8 |
import {CustomOptions} from "../../services/servicesUtils/customOptions.class"; |
|
5 | 9 |
|
6 |
|
|
7 | 10 |
@Injectable() |
8 | 11 |
export class SubscribeService { |
9 | 12 |
|
10 |
constructor(private http:Http) { |
|
13 |
constructor(private http:HttpClient) {
|
|
11 | 14 |
} |
12 | 15 |
getCommunitySubscribers(pid:string, url:string){ |
13 |
return this.http.get(url+"/community/"+pid+"/subscribers")
|
|
14 |
.map(res => <any> res.json()); |
|
16 |
return this.http.get<any>(url+"/community/"+pid+"/subscribers");
|
|
17 |
//.map(res => <any> res.json());
|
|
15 | 18 |
} |
16 | 19 |
|
17 | 20 |
isSubscribedToCommunity(pid:string, email:string, url:string){ |
18 | 21 |
return this.http.get(url+"/community/"+pid+"/subscribers") |
19 |
.map(res => ((<any>res =="")?{}:<any> res.json())) |
|
22 |
//.map(res => ((<any>res =="")?{}:<any> res.json()))
|
|
20 | 23 |
|
21 |
.map(res => {
|
|
22 |
if(res.status && res.status != 200) {
|
|
24 |
.pipe(map(res => {
|
|
25 |
if(res['status'] && res['status'] != 200) {
|
|
23 | 26 |
return null; |
24 | 27 |
} |
25 |
if(res.subscribers && res.subscribers != null){
|
|
28 |
if(res['subscribers'] && res['subscribers'] != null){
|
|
26 | 29 |
|
27 |
for(var i =0; i< res.subscribers.length; i++ ){
|
|
28 |
if(res.subscribers[i]!=null && res.subscribers[i].email == email){
|
|
30 |
for(var i =0; i< res['subscribers'].length; i++ ){
|
|
31 |
if(res['subscribers'][i]!=null && res['subscribers'][i].email == email){
|
|
29 | 32 |
return true; |
30 | 33 |
} |
31 | 34 |
} |
32 | 35 |
} |
33 | 36 |
return false; |
34 | 37 |
|
35 |
}); |
|
38 |
}));
|
|
36 | 39 |
} |
37 | 40 |
subscribeToCommunity(pid:string, email:string, url:string){ |
38 | 41 |
var subscriber = {"email":email}; |
39 |
return this.http.post(url+"/community/"+pid+"/subscribers", JSON.stringify(subscriber), this.getAuthOptionsWithBody())
|
|
40 |
.map(res => <any> res.json()); |
|
42 |
return this.http.post<any>(url+"/community/"+pid+"/subscribers", JSON.stringify(subscriber), CustomOptions.getAuthOptionsWithBody());
|
|
43 |
//.map(res => <any> res.json());
|
|
41 | 44 |
} |
42 | 45 |
unSubscribeToCommunity(pid:string, email:string, url:string){ |
43 | 46 |
|
44 |
return this.http.post(url+"/community/"+pid+"/subscribers/delete", JSON.stringify([email]), this.getAuthOptionsWithBody())
|
|
45 |
.map(res => <any> res.json()); |
|
47 |
return this.http.post<any>(url+"/community/"+pid+"/subscribers/delete", JSON.stringify([email]), CustomOptions.getAuthOptionsWithBody());
|
|
48 |
//.map(res => <any> res.json());
|
|
46 | 49 |
} |
47 | 50 |
getCommunitiesSubscribedTo(email:string, url:string){ |
48 |
return this.http.get(url+"/subscriber/communities?email="+email)
|
|
49 |
.map(res => <any> res.json()); |
|
51 |
return this.http.get<any>(url+"/subscriber/communities?email="+email);
|
|
52 |
//.map(res => <any> res.json());
|
|
50 | 53 |
} |
51 | 54 |
|
55 |
/* |
|
52 | 56 |
public getAuthOptionsWithBody():RequestOptions{ |
53 | 57 |
let headers = new Headers(); |
54 | 58 |
headers.append('Content-Type', 'application/json'); |
... | ... | |
56 | 60 |
let options = new RequestOptions({ headers: headers, withCredentials:true }); |
57 | 61 |
return options; |
58 | 62 |
} |
63 |
*/ |
|
59 | 64 |
|
65 |
public getAuthOptionsWithBody():any { |
|
66 |
return { |
|
67 |
headers: new HttpHeaders({ |
|
68 |
'Content-Type': 'application/json', |
|
69 |
'X-XSRF-TOKEN': COOKIE.getCookie(COOKIE.cookieName_id) |
|
70 |
}), withCredentials: true |
|
71 |
}; |
|
72 |
} |
|
60 | 73 |
} |
Also available in: Unified diff
[Library|Trunk]
Merge into trunk branch angular7 rev 55729