Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

159 #162

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

159 #162

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions stackle-app/src/app/secure/common-feed/common-feed.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

import { PostService } from '../../services/post.service';
import { UserService } from '../../services/user.service';

@Component({
selector: 'app-common-feed',
Expand All @@ -15,7 +16,8 @@ export class CommonFeedComponent implements OnInit {

constructor(
private router: Router,
private postService: PostService
private postService: PostService,
private userService: UserService
) { }

ngOnInit() {
Expand All @@ -24,7 +26,7 @@ export class CommonFeedComponent implements OnInit {
}

private navigateToPost(post_id) {
this.router.navigate(['app/post/'+post_id]);
this.router.navigate(['app/post/' + post_id]);
}

getAllPosts() {
Expand All @@ -38,9 +40,18 @@ export class CommonFeedComponent implements OnInit {
}

voteUp(id) {
this.postService.voteUp(id).subscribe( response => {
this.getAllPosts();
})
this.userService.getUser(localStorage.getItem('username')).subscribe((data) => {
//we have to push object id from document of this user so we have to pass that object id to backed
// we also have changed postService
this.postService.voteUp(id,data.result._id).subscribe(response => {
this.getAllPosts();
});
}, (err) => {

}, () => {
console.log("Completed");
});

}

}
14 changes: 11 additions & 3 deletions stackle-app/src/app/secure/shared/post/post.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Router, ActivatedRoute, Params } from '@angular/router';
import { PostService } from '../../../services/post.service';
import { MatSnackBar } from '@angular/material';
import {ProfileService} from "../../../services/profile.service";
import { UserService } from '../../../services/user.service';

@Component({
selector: 'app-post',
Expand All @@ -21,7 +22,8 @@ export class PostComponent implements OnInit {
private profileService: ProfileService,
private router: Router,
private activatedRoute: ActivatedRoute,
private snackBar: MatSnackBar
private snackBar: MatSnackBar,
private userService: UserService
) { }

ngOnInit() {
Expand Down Expand Up @@ -65,8 +67,14 @@ export class PostComponent implements OnInit {
}

voteOnPost(){
this.postService.voteUp(this.postId).subscribe( response => {
this.getPostData();
this.userService.getUser(localStorage.getItem('username')).subscribe((data) => {
this.postService.voteUp(this.postId,data.result._id).subscribe(response => {
this.getPostData();
});
}, (err) => {

}, () => {
console.log("Completed");
});
}

Expand Down
4 changes: 2 additions & 2 deletions stackle-app/src/app/services/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export class PostService {
return this.http.post(`${this.apiUrl}/api/post/create`, postObject);
}

voteUp(id) {
return this.http.post(`${this.apiUrl}/api/post/likes/up/${id}`, {userId:localStorage.getItem('username')});
voteUp(id,u_id) {
return this.http.post(`${this.apiUrl}/api/post/likes/up/${id}`, {userId:u_id});
}

voteDown(id) {
Expand Down
6 changes: 5 additions & 1 deletion stackle_api/app/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,11 @@ postSchema.statics.setLikeUp = function(request, response) {
var check = likeArray.indexOf(currentUserId);

if (check === -1) {
result.likes.push(currentUserId);
// result.likes.push(currentUserId)
// here instead of pushing currentuserID which you are sending github username in string we have to push
// object id of that user from user schema that is why server carshes because you are pushing string to array
// of mongoose.Schema.Types.ObjectId
result.likes.push(mongoose.Types.ObjectId(currentUserId));
result.save(function(err) {
if (err)
return returnWithResponse.configureReturnData({
Expand Down
3 changes: 2 additions & 1 deletion stackle_api/config/database.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
url: process.env.LOCAL_DB || "mongodb://localhost/main",
// url: process.env.LOCAL_DB || "mongodb://localhost/main",
url: process.env.LOCAL_DB || "mongodb://mongo:27017/stackle",
testurl: "mongodb://localhost/node-test",
alturl: "mongodb://ordinary:[email protected]:49201/stackle",
option: function(version) {
Expand Down