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