ApiPostController.prototype.updateLike = function(postId, postLikeId, callback) { var apiPost = this; var Post = require('app/models/post'); Post.findById(postId).exec(function(err, post) { if (!err) { var index = post.ref_post_like.indexOf(postLikeId); if (index == -1) { post.ref_post_like.push(postLikeId); } else { post.ref_post_like.splice(index, 1); } post.save(function(err, post) { apiPost.updateWallPost(err, post, callback); }); } else { callback(err); } }); };
ApiPostController.prototype.put = function() { if (this.isValidPut()) { var apiPost = this; var Post = require('app/models/post'); Post.findById(this.req.params.id).exec(function(err, post) { apiPost.putCallback(err, post); }); } };
ApiPostController.prototype.addComment = function(postId, commentId, callback) { var apiPost = this; var Post = require('app/models/post'); Post.findById(postId).exec(function(err, post) { if (!err) { post.ref_comment.push(commentId); post.save(function(err, post) { apiPost.updateWallPost(err, post, callback); }); } else { callback(err); } }); };