Last active
October 8, 2015 03:48
-
-
Save melissamarima/b6ed4a3570738c1636a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// models/Post.js mongoose schema for mongoDB | |
PostSchema.methods.upvote = function(cb) { | |
this.upvotes += 1; | |
this.save(cb); | |
}; | |
// Now we create the route in our index.js: | |
router.put('/posts/:post/upvote', function(req, res, next) { | |
req.post.upvote(function(err, post){ | |
if (err) { return next(err); } | |
res.json(post); | |
}); | |
}); | |
// source https://thinkster.io/mean-stack-tutorial#getting-user-input-enable-upvoting |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment