@ -21,13 +21,15 @@ export class FeedService {
private mostLikedOffset = 0 ;
private mostLikedOffset = 0 ;
private newOffset = 0 ;
private newOffset = 0 ;
constructor ( private http : HttpClient ) { }
constructor ( private http : HttpClient ) {
}
public createPost ( pContent : String ) {
public createPost ( pContent : String ) {
const headers = new Headers ( ) ;
const headers = new Headers ( ) ;
headers . set ( 'Content-Type' , 'application/json' ) ;
headers . set ( 'Content-Type' , 'application/json' ) ;
const body = { query : ` mutation( $ content: String!) {
const body = {
query : ` mutation( $ content: String!) {
createPost ( content : $content ) {
createPost ( content : $content ) {
id ,
id ,
content ,
content ,
@ -50,7 +52,8 @@ export class FeedService {
createdAt }
createdAt }
} ` , variables: {
} ` , variables: {
content : pContent
content : pContent
} } ;
}
} ;
return this . http . post ( environment . graphQLUrl , body ) . pipe ( tap ( response = > {
return this . http . post ( environment . graphQLUrl , body ) . pipe ( tap ( response = > {
const updatedposts = this . newPosts . getValue ( ) ;
const updatedposts = this . newPosts . getValue ( ) ;
updatedposts . unshift ( this . renderPost ( response ) ) ;
updatedposts . unshift ( this . renderPost ( response ) ) ;
@ -63,7 +66,8 @@ export class FeedService {
const headers = new Headers ( ) ;
const headers = new Headers ( ) ;
headers . set ( 'Content-Type' , 'application/json' ) ;
headers . set ( 'Content-Type' , 'application/json' ) ;
const body = { query : ` mutation( $ content: String!, $ id: ID) {
const body = {
query : ` mutation( $ content: String!, $ id: ID) {
createPost ( content : $content activityId : $id ) {
createPost ( content : $content activityId : $id ) {
id ,
id ,
content ,
content ,
@ -87,7 +91,8 @@ export class FeedService {
} ` , variables: {
} ` , variables: {
content : pContent ,
content : pContent ,
id : activityId
id : activityId
} } ;
}
} ;
return this . http . post ( environment . graphQLUrl , body ) . pipe ( tap ( response = > {
return this . http . post ( environment . graphQLUrl , body ) . pipe ( tap ( response = > {
const updatedposts = this . newPosts . getValue ( ) ;
const updatedposts = this . newPosts . getValue ( ) ;
updatedposts . unshift ( this . renderPost ( response ) ) ;
updatedposts . unshift ( this . renderPost ( response ) ) ;
@ -100,13 +105,15 @@ export class FeedService {
const headers = new Headers ( ) ;
const headers = new Headers ( ) ;
headers . set ( 'Content-Type' , 'application/json' ) ;
headers . set ( 'Content-Type' , 'application/json' ) ;
const body = { query : ` mutation( $ postId: ID!) {
const body = {
query : ` mutation( $ postId: ID!) {
vote ( postId : $postId , type : UPVOTE ) {
vote ( postId : $postId , type : UPVOTE ) {
post { userVote upvotes downvotes }
post { userVote upvotes downvotes }
}
}
} ` , variables: {
} ` , variables: {
postId
postId
} } ;
}
} ;
return this . http . post ( environment . graphQLUrl , body ) ;
return this . http . post ( environment . graphQLUrl , body ) ;
}
}
@ -115,13 +122,15 @@ export class FeedService {
const headers = new Headers ( ) ;
const headers = new Headers ( ) ;
headers . set ( 'Content-Type' , 'application/json' ) ;
headers . set ( 'Content-Type' , 'application/json' ) ;
const body = { query : ` mutation( $ postId: ID!) {
const body = {
query : ` mutation( $ postId: ID!) {
vote ( postId : $postId , type : DOWNVOTE ) {
vote ( postId : $postId , type : DOWNVOTE ) {
post { userVote upvotes downvotes }
post { userVote upvotes downvotes }
}
}
} ` , variables: {
} ` , variables: {
postId : pPostID
postId : pPostID
} } ;
}
} ;
return this . http . post ( environment . graphQLUrl , body ) ;
return this . http . post ( environment . graphQLUrl , body ) ;
}
}
@ -130,11 +139,13 @@ export class FeedService {
const headers = new Headers ( ) ;
const headers = new Headers ( ) ;
headers . set ( 'Content-Type' , 'application/json' ) ;
headers . set ( 'Content-Type' , 'application/json' ) ;
const body = { query : ` mutation( $ postId: ID!) {
const body = {
query : ` mutation( $ postId: ID!) {
deletePost ( postId : $postId )
deletePost ( postId : $postId )
} ` , variables: {
} ` , variables: {
postId : pPostID
postId : pPostID
} } ;
}
} ;
return this . http . post ( environment . graphQLUrl , body ) ;
return this . http . post ( environment . graphQLUrl , body ) ;
}
}
@ -153,7 +164,8 @@ export class FeedService {
}
}
this . setPost ( sort ) ;
this . setPost ( sort ) ;
} ) ;
} ) ;
} this . setPost ( sort ) ;
}
this . setPost ( sort ) ;
}
}
public getNextPosts() {
public getNextPosts() {
@ -198,7 +210,8 @@ export class FeedService {
}
}
buildJson ( sort : string , offset : number ) {
buildJson ( sort : string , offset : number ) {
const body = { query : ` query( $ offset: Int, $ sort: SortType){
const body = {
query : ` query( $ offset: Int, $ sort: SortType){
getPosts ( first : 10 , offset : $offset , sort : $sort ) {
getPosts ( first : 10 , offset : $offset , sort : $sort ) {
id ,
id ,
content ,
content ,
@ -222,7 +235,8 @@ export class FeedService {
} ` , variables: {
} ` , variables: {
offset ,
offset ,
sort
sort
} } ;
}
} ;
return body ;
return body ;
}
}
@ -251,7 +265,9 @@ export class FeedService {
post . activity . name ,
post . activity . name ,
post . activity . description ,
post . activity . description ,
post . activity . points ) ;
post . activity . points ) ;
} else { activity = null ; }
} else {
activity = null ;
}
return new Post ( id , content , htmlContent , upvotes , downvotes , userVote , deletable , date , author , activity ) ;
return new Post ( id , content , htmlContent , upvotes , downvotes , userVote , deletable , date , author , activity ) ;
}
}
@ -283,7 +299,9 @@ export class FeedService {
post . activity . name ,
post . activity . name ,
post . activity . description ,
post . activity . description ,
post . activity . points ) ;
post . activity . points ) ;
} else { activity = null ; }
} else {
activity = null ;
}
posts . push ( new Post ( id , content , htmlContent , upvotes , downvotes , userVote , deletable , date , author , activity ) ) ;
posts . push ( new Post ( id , content , htmlContent , upvotes , downvotes , userVote , deletable , date , author , activity ) ) ;
}
}
return posts ;
return posts ;