Loading comments/app.js +2 −2 Original line number Diff line number Diff line Loading @@ -92,11 +92,11 @@ 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) limit: parseInt(req.query.limit, 10), orderBy: req.query.sortByScore ? "vote" : "created_at" }; new Request(req).getRecentComments(query, function(comments) { res.json(comments); Loading comments/comments.js +5 −1 Original line number Diff line number Diff line Loading @@ -105,17 +105,21 @@ Comments.prototype = { * @param {Object} opts Options for the query: * @param {Number} [opts.limit=100] Number of rows to return. * @param {Number} [opts.offset=0] The starting index. * @param {Number} [opts.orderBy="created_at"] By which column to sort the results. * Two possible options here: "created_at" and "vote". * * @param {Function} callback Called with the result. * @param {Error} callback.err The error object. * @param {Object[]} callback.comments An array of comment rows. */ findRecent: function(opts, callback) { opts.orderBy = opts.orderBy || "created_at"; var sql = [ 'SELECT ', this.fields.join(", "), 'FROM', this.view, 'WHERE domain = ?', 'ORDER BY created_at DESC', 'ORDER BY '+opts.orderBy+' DESC', 'LIMIT ? OFFSET ?' ]; Loading comments/comments.spec.js +7 −0 Original line number Diff line number Diff line Loading @@ -144,6 +144,13 @@ describe("Comments", function() { }); }); it("#findRecent with orderBy:vote sorts to highest voted comment to top", function(done) { comments.findRecent({orderBy: "vote"}, function(err, rows) { expect(rows[0].vote).toEqual(4); done(); }); }); it("#count gets total number of comments in current domain", function(done) { comments.count({}, function(err, cnt) { expect(cnt).toEqual(24); Loading Loading
comments/app.js +2 −2 Original line number Diff line number Diff line Loading @@ -92,11 +92,11 @@ 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) limit: parseInt(req.query.limit, 10), orderBy: req.query.sortByScore ? "vote" : "created_at" }; new Request(req).getRecentComments(query, function(comments) { res.json(comments); Loading
comments/comments.js +5 −1 Original line number Diff line number Diff line Loading @@ -105,17 +105,21 @@ Comments.prototype = { * @param {Object} opts Options for the query: * @param {Number} [opts.limit=100] Number of rows to return. * @param {Number} [opts.offset=0] The starting index. * @param {Number} [opts.orderBy="created_at"] By which column to sort the results. * Two possible options here: "created_at" and "vote". * * @param {Function} callback Called with the result. * @param {Error} callback.err The error object. * @param {Object[]} callback.comments An array of comment rows. */ findRecent: function(opts, callback) { opts.orderBy = opts.orderBy || "created_at"; var sql = [ 'SELECT ', this.fields.join(", "), 'FROM', this.view, 'WHERE domain = ?', 'ORDER BY created_at DESC', 'ORDER BY '+opts.orderBy+' DESC', 'LIMIT ? OFFSET ?' ]; Loading
comments/comments.spec.js +7 −0 Original line number Diff line number Diff line Loading @@ -144,6 +144,13 @@ describe("Comments", function() { }); }); it("#findRecent with orderBy:vote sorts to highest voted comment to top", function(done) { comments.findRecent({orderBy: "vote"}, function(err, rows) { expect(rows[0].vote).toEqual(4); done(); }); }); it("#count gets total number of comments in current domain", function(done) { comments.count({}, function(err, cnt) { expect(cnt).toEqual(24); Loading