Loading comments/api_adapter.js +1 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ module.exports = { return { _id: comment.id, author: comment.username, target: this.targetToJson(comment), content: comment.content, contentHtml: comment.content_html, createdAt: String(comment.created_at), Loading comments/app.js +12 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,18 @@ app.post('/auth/logout', validator.doLogout, function(req, res) { // Requests for Comments // Returns n most recent comments. // Takes two parameters: offset and limit. app.get('/auth/:sdk/:version/comments_recent', function(req, res) { var query = { offset: parseInt(req.query.offset, 10), limit: parseInt(req.query.limit, 10) }; new Request(req).getRecentComments(query, function(comments) { res.json(comments); }); }); // Returns number of comments for each class/member, // and when user is logged in, all his subscriptions. app.get('/auth/:sdk/:version/comments_meta', function(req, res) { Loading comments/request.js +21 −2 Original line number Diff line number Diff line Loading @@ -21,6 +21,25 @@ Request.prototype = { this.db.users().login(user, pass, callback); }, getRecentComments: function(query, callback) { this.db.comments().findRecent(query, function(err, comments) { this.db.comments().count(query, function(err, total) { var commentsOut = comments.map(ApiAdapter.commentToJson, ApiAdapter); // store total count to last comment. // It's a hack, but that's what we're left with for now. var last = commentsOut[commentsOut.length-1]; if (last) { last.total_rows = total; last.offset = query.offset; last.limit = query.limit; } callback(commentsOut); }); }.bind(this)); }, getCommentCountsPerTarget: function(callback) { this.db.comments().countsPerTarget(function(err, counts) { callback(counts); Loading @@ -38,7 +57,7 @@ Request.prototype = { } this.db.comments().find(targetObj, function(err, comments) { callback(comments.map(ApiAdapter.commentToJson)); callback(comments.map(ApiAdapter.commentToJson, ApiAdapter)); }); }, Loading Loading @@ -127,7 +146,7 @@ Request.prototype = { } this.db.subscriptions().findTargetsByUser(this.getUserId(), function(err, targets) { callback(targets.map(ApiAdapter.targetToJson)); callback(targets.map(ApiAdapter.targetToJson, ApiAdapter)); }); }, Loading Loading
comments/api_adapter.js +1 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ module.exports = { return { _id: comment.id, author: comment.username, target: this.targetToJson(comment), content: comment.content, contentHtml: comment.content_html, createdAt: String(comment.created_at), Loading
comments/app.js +12 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,18 @@ app.post('/auth/logout', validator.doLogout, function(req, res) { // Requests for Comments // Returns n most recent comments. // Takes two parameters: offset and limit. app.get('/auth/:sdk/:version/comments_recent', function(req, res) { var query = { offset: parseInt(req.query.offset, 10), limit: parseInt(req.query.limit, 10) }; new Request(req).getRecentComments(query, function(comments) { res.json(comments); }); }); // Returns number of comments for each class/member, // and when user is logged in, all his subscriptions. app.get('/auth/:sdk/:version/comments_meta', function(req, res) { Loading
comments/request.js +21 −2 Original line number Diff line number Diff line Loading @@ -21,6 +21,25 @@ Request.prototype = { this.db.users().login(user, pass, callback); }, getRecentComments: function(query, callback) { this.db.comments().findRecent(query, function(err, comments) { this.db.comments().count(query, function(err, total) { var commentsOut = comments.map(ApiAdapter.commentToJson, ApiAdapter); // store total count to last comment. // It's a hack, but that's what we're left with for now. var last = commentsOut[commentsOut.length-1]; if (last) { last.total_rows = total; last.offset = query.offset; last.limit = query.limit; } callback(commentsOut); }); }.bind(this)); }, getCommentCountsPerTarget: function(callback) { this.db.comments().countsPerTarget(function(err, counts) { callback(counts); Loading @@ -38,7 +57,7 @@ Request.prototype = { } this.db.comments().find(targetObj, function(err, comments) { callback(comments.map(ApiAdapter.commentToJson)); callback(comments.map(ApiAdapter.commentToJson, ApiAdapter)); }); }, Loading Loading @@ -127,7 +146,7 @@ Request.prototype = { } this.db.subscriptions().findTargetsByUser(this.getUserId(), function(err, targets) { callback(targets.map(ApiAdapter.targetToJson)); callback(targets.map(ApiAdapter.targetToJson, ApiAdapter)); }); }, Loading