summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2015-01-24 20:53:07 -0700
committermo khan <mo@mokhan.ca>2015-01-24 20:53:07 -0700
commit9d3f0000c1d9d694953fca754c339098fcd176ab (patch)
tree7d1d9c5a7aebf1309d29074a35106ed06ad455ba
parent0e3901c6c90ee36d3a08c37b24fd2eacc944e4b8 (diff)
insert comment.
-rw-r--r--week-3/hw3-2and3-3/blog/posts.js26
1 files changed, 14 insertions, 12 deletions
diff --git a/week-3/hw3-2and3-3/blog/posts.js b/week-3/hw3-2and3-3/blog/posts.js
index c006ac9..c34cfea 100644
--- a/week-3/hw3-2and3-3/blog/posts.js
+++ b/week-3/hw3-2and3-3/blog/posts.js
@@ -30,15 +30,15 @@ function PostsDAO(db) {
"date": new Date()
};
- // now insert the post
- posts.insert(post, function (err, result) {
- "use strict";
-
- if (err) {
- return callback(err, null);
- }
- return callback(null, permalink);
- });
+ // now insert the post
+ posts.insert(post, function (err, result) {
+ "use strict";
+
+ if (err) {
+ return callback(err, null);
+ }
+ return callback(null, permalink);
+ });
};
this.getPosts = function(num, callback) {
@@ -89,9 +89,11 @@ function PostsDAO(db) {
comment['email'] = email
}
- // hw3.3 TODO
- callback(Error("addComment NYI"), null);
- }
+ posts.update({ 'permalink': permalink }, { '$push': { comments: comment } }, function(error, updated){
+ if (error) return callback(error, null);
+ callback(error, updated);
+ });
+ };
}
module.exports.PostsDAO = PostsDAO;