Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Kolejność wywołania metod:
- // PostComponent.vote => VoteService.voteOnPost => VoteService.vote
- // czyli w sumie od góry do dołu
- export class PostsComponent implements OnInit {
- async vote(id: string) {
- const post = this.posts.find(value => value.id === id);
- const index = this.posts.indexOf(post);
- const votes = await VoteService.voteOnPost(this.http, id)
- .then(value => {
- return value;
- });
- console.log(votes);
- console.log(votes.votes);
- this.posts[index] = post;
- }
- }
- export class VoteService {
- static voteOnPost(http: HttpClient, id: string) {
- return this.vote(http, 'post', id).then(value => {return value});
- }
- private static async vote(http: HttpClient, onWhat: string, id: string) {
- const resp: any = new Post();
- await http.get("http://localhost:8080/vote/" + onWhat + "/" + id,
- {headers: {'Authorization': localStorage.getItem('Authorization')}})
- .subscribe(
- (response: number) => resp.votes = response,
- error => console.log(error));
- return resp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement