Commit 298edc67 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Loading list of all available tags from backend.

parent 2cc8d3e9
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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() {
+7 −0
Original line number Diff line number Diff line
@@ -372,6 +372,13 @@ Comments.prototype = {
        });
    },

    /**
     * @inheritdoc Tags#getAll
     */
    getAllTags: function(callback) {
        this.tags.getAll(callback);
    },

    /**
     * @inheritdoc Tags#add
     */
+9 −0
Original line number Diff line number Diff line
@@ -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.
     */
+18 −0
Original line number Diff line number Diff line
@@ -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.
     *
+16 −0
Original line number Diff line number Diff line
@@ -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