Loading comments/app.js +7 −0 Original line number Diff line number Diff line Loading @@ -220,6 +220,13 @@ app.post('/auth/:sdk/:version/comments/:commentId/remove_tag', Auth.isLoggedIn, }); }); // Returns list of all available tags app.get('/auth/:sdk/:version/tags', function(req, res) { new Request(req).getAllTags(function(tags) { res.send({ success: true, tags: tags }); }); }); // Marks a comment 'read' app.post('/auth/:sdk/:version/comments/:commentId/read', Auth.isLoggedIn, function(req, res) { new Request(req).markRead(req.params.commentId, function() { Loading comments/lib/comments.js +7 −0 Original line number Diff line number Diff line Loading @@ -372,6 +372,13 @@ Comments.prototype = { }); }, /** * @inheritdoc Tags#getAll */ getAllTags: function(callback) { this.tags.getAll(callback); }, /** * @inheritdoc Tags#add */ Loading comments/lib/request.js +9 −0 Original line number Diff line number Diff line Loading @@ -198,6 +198,15 @@ Request.prototype = { }); }, /** * Retrieves array of all tags. */ getAllTags: function(callback) { this.db.comments().getAllTags(function(err, tags) { callback(tags); }); }, /** * Adds tag to comment. */ Loading comments/lib/tags.js +18 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,24 @@ function Tags(db, domain) { } Tags.prototype = { /** * Retrieves all available tags in current domain. * * @param {Function} callback * @param {Error} callback.err * @param {Object[]} callback.tags Array of object with single `tagname` field. */ getAll: function(callback) { var sql = "SELECT tagname FROM tags WHERE domain = ? ORDER BY tagname"; this.db.query(sql, [this.domain], function(err, rows) { if (err) { callback(err); return; } callback(null, rows.map(function(r) { return {tagname: r.tagname}; })); }); }, /** * Adds tag to the comment. * Loading comments/spec/tags.spec.js +16 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,22 @@ describe("Tags", function() { connection.end(); }); it("#getAllTags returns all tags in current domain", function(done) { comments.getAllTags(function(err, tags) { expect(tags).toEqual([{tagname: "bug"}, {tagname: "feature"}]); done(); }); }); it("#getAllTags returns empty array when no tags in current domain", function(done) { comments = new Comments(new DbFacade(connection), "blabla"); comments.getAllTags(function(err, tags) { expect(tags).toEqual([]); done(); }); }); it("each comment has concatenated list of tags", function(done) { comments.getById(1, function(err, com) { expect(com.tags).toEqual("bug\tfeature"); Loading Loading
comments/app.js +7 −0 Original line number Diff line number Diff line Loading @@ -220,6 +220,13 @@ app.post('/auth/:sdk/:version/comments/:commentId/remove_tag', Auth.isLoggedIn, }); }); // Returns list of all available tags app.get('/auth/:sdk/:version/tags', function(req, res) { new Request(req).getAllTags(function(tags) { res.send({ success: true, tags: tags }); }); }); // Marks a comment 'read' app.post('/auth/:sdk/:version/comments/:commentId/read', Auth.isLoggedIn, function(req, res) { new Request(req).markRead(req.params.commentId, function() { Loading
comments/lib/comments.js +7 −0 Original line number Diff line number Diff line Loading @@ -372,6 +372,13 @@ Comments.prototype = { }); }, /** * @inheritdoc Tags#getAll */ getAllTags: function(callback) { this.tags.getAll(callback); }, /** * @inheritdoc Tags#add */ Loading
comments/lib/request.js +9 −0 Original line number Diff line number Diff line Loading @@ -198,6 +198,15 @@ Request.prototype = { }); }, /** * Retrieves array of all tags. */ getAllTags: function(callback) { this.db.comments().getAllTags(function(err, tags) { callback(tags); }); }, /** * Adds tag to comment. */ Loading
comments/lib/tags.js +18 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,24 @@ function Tags(db, domain) { } Tags.prototype = { /** * Retrieves all available tags in current domain. * * @param {Function} callback * @param {Error} callback.err * @param {Object[]} callback.tags Array of object with single `tagname` field. */ getAll: function(callback) { var sql = "SELECT tagname FROM tags WHERE domain = ? ORDER BY tagname"; this.db.query(sql, [this.domain], function(err, rows) { if (err) { callback(err); return; } callback(null, rows.map(function(r) { return {tagname: r.tagname}; })); }); }, /** * Adds tag to the comment. * Loading
comments/spec/tags.spec.js +16 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,22 @@ describe("Tags", function() { connection.end(); }); it("#getAllTags returns all tags in current domain", function(done) { comments.getAllTags(function(err, tags) { expect(tags).toEqual([{tagname: "bug"}, {tagname: "feature"}]); done(); }); }); it("#getAllTags returns empty array when no tags in current domain", function(done) { comments = new Comments(new DbFacade(connection), "blabla"); comments.getAllTags(function(err, tags) { expect(tags).toEqual([]); done(); }); }); it("each comment has concatenated list of tags", function(done) { comments.getById(1, function(err, com) { expect(com.tags).toEqual("bug\tfeature"); Loading