@ -29,33 +29,33 @@ export class FeedService {
}
}
public upvote ( pPostID : number ) : any {
public upvote ( pPostID : number ) : any {
const url = environment . graphQLUrl ;
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 }
}
} ` , variables: {
} ` , variables: {
postId : pPostID
postId : pPostID
} } ;
} } ;
return this . http . post ( u rl, body ) ;
return this . http . post ( environment. graphQLU rl, body ) ;
}
}
public downvote ( pPostID : number ) : any {
public downvote ( pPostID : number ) : any {
const url = environment . graphQLUrl ;
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 }
}
} ` , variables: {
} ` , variables: {
postId : pPostID
postId : pPostID
} } ;
} } ;
return this . http . post ( u rl, body ) ;
return this . http . post ( environment. graphQLU rl, body ) ;
}
}
public deletePost ( pPostID : number ) : any {
public deletePost ( pPostID : number ) : any {
@ -83,74 +83,32 @@ export class FeedService {
} ) ;
} ) ;
return this . posts ;
return this . posts ;
}
}
public getAllPostsById ( userId : number ) : Array < Post > {
const url = environment . graphQLUrl ;
const headers = new Headers ( ) ;
headers . set ( 'Content-Type' , 'application/json' ) ;
this . http . post ( url , this . getBodyForGetAllPostsByUserId ( userId ) )
. subscribe ( response = > {
this . posts = this . renderAllPosts ( response . json ( ) ) ;
} ) ;
return this . posts ;
}
public getAllPostsRaw ( ) : any {
public getAllPostsRaw ( ) : any {
const url = environment . graphQLUrl ;
const headers = new Headers ( ) ;
const headers = new Headers ( ) ;
headers . set ( 'Content-Type' , 'application/json' ) ;
headers . set ( 'Content-Type' , 'application/json' ) ;
return this . http . post ( environment . graphQLUrl , this . getBodyForGetAllPosts ( ) ) ;
return this . http . post ( url , this . getBodyForGetAllPosts ( ) ) ;
}
}
public getAllPostsRawByUserId ( userId : number ) : any {
getBodyForGetAllPosts() {
const url = environment . graphQLUrl ;
const body = { query : ` {
const headers = new Headers ( ) ;
headers . set ( 'Content-Type' , 'application/json' ) ;
return this . http . post ( url , this . getBodyForGetAllPostsByUserId ( userId ) ) ;
}
getBodyForGetAllPostsByUserId ( pUserId : number ) {
const body = { query : ` query ( $ userId: ID!) {
getPosts ( first : 1000 , offset : 0 ) {
getPosts ( first : 1000 , offset : 0 ) {
id ,
id ,
content ,
content ,
htmlContent ,
htmlContent ,
upvotes ,
upvotes ,
downvotes ,
downvotes ,
userVote (userId : $userId ) ,
userVote ,
deletable ( userId : $userId )
deletable
author {
author {
name ,
name ,
handle ,
handle ,
id } ,
id } ,
createdAt }
createdAt }
} ` , variables: {
} ` , variables: {
userId : pUserId
} } ;
} } ;
return body ;
return body ;
}
}
getBodyForGetAllPosts() {
const body = { query : ` query {
getPosts ( first : 1000 , offset : 0 ) {
id ,
content ,
htmlContent ,
upvotes ,
downvotes ,
author {
name ,
handle ,
id } ,
createdAt }
} `
} ;
return body ;
}
public renderAllPosts ( pResponse : any ) : Array < Post > {
public renderAllPosts ( pResponse : any ) : Array < Post > {
const posts = new Array < Post > ( ) ;
const posts = new Array < Post > ( ) ;