From 71a517d882c805a9e897c2883f14c061915a46bb Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Thu, 30 Aug 2012 10:15:00 +0300 Subject: [PATCH] Implement Comments#setDeleted method. --- comments/comments.js | 28 ++++++++++++++++++++++++++++ comments/comments.spec.js | 9 +++++++++ 2 files changed, 37 insertions(+) diff --git a/comments/comments.js b/comments/comments.js index 02c4a030..552efbfd 100644 --- a/comments/comments.js +++ b/comments/comments.js @@ -204,6 +204,34 @@ Comments.prototype = { created_at: new Date() }, callback); }.bind(this)); + }, + + /** + * Marks comment as deleted. + * + * @param {Object} action A delete action: + * @param {Number} action.id ID of the comment to delete. + * @param {Number} action.user_id ID of the user doing the delete. + * @param {Error} callback.err The error object. + * @param {Function} callback Called when done. + */ + setDeleted: function(action, callback) { + var data = { + id: action.id, + deleted: 1 + }; + this.db.update("comments", data, function(err) { + if (err) { + callback(err); + return; + } + this.db.insert("updates", { + comment_id: action.id, + user_id: action.user_id, + action: 'delete', + created_at: new Date() + }, callback); + }.bind(this)); } }; diff --git a/comments/comments.spec.js b/comments/comments.spec.js index df183129..7b033fc6 100644 --- a/comments/comments.spec.js +++ b/comments/comments.spec.js @@ -187,4 +187,13 @@ describe("Comments", function() { }); }); + it("#setDeleted marks comment as deleted, so it can't be accessed any more", function(done) { + comments.setDeleted({id: 10, user_id: 1}, function(err) { + comments.getById(10, function(err, newCom) { + expect(newCom).toEqual(null); + done(); + }); + }); + }); + }); -- GitLab