summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-09-04 23:37:33 -0400
committerJules Laplace <jules@okfoc.us>2015-09-04 23:37:33 -0400
commit0d0c04ad510264f2dbd2deb3bbf0b0d0c0605a62 (patch)
treecde48b2e1db249f61edafc28fd649aed22583fd4
parentb2d2bc1c592f5263ed30c26b6a8ea5f48e230e90 (diff)
get hootbox
-rw-r--r--lib/bucky.js10
-rw-r--r--lib/db/index.js12
-rw-r--r--lib/index.js2
3 files changed, 21 insertions, 3 deletions
diff --git a/lib/bucky.js b/lib/bucky.js
index ef822c4..aed6494 100644
--- a/lib/bucky.js
+++ b/lib/bucky.js
@@ -37,7 +37,15 @@ var bucky = module.exports = {
})
next()
})
- },
+ },
+ ensureHootbox: function (req, res, next){
+ db.getCommentsForThread(1, 50).then(function(hootbox){
+ res.hootbox = hootbox.forEach(function(comment){
+ comment.set("comment", comment.get("comment").toString() )
+ })
+ next()
+ })
+ },
/* DETAILS */
diff --git a/lib/db/index.js b/lib/db/index.js
index 8e72d34..2c8486b 100644
--- a/lib/db/index.js
+++ b/lib/db/index.js
@@ -74,8 +74,16 @@ db.getFileSizes = function(ids){
}
/* COMMENTS */
-db.getCommentsForThread = function (id){
- return Comment.query("where", "thread", "=", id).fetchAll()
+db.getCommentsForThread = function (id, limit, offset){
+ return Comment.query(function(qb){
+ qb.where("thread", "=", id).orderBy("id", "desc")
+ if (limit) {
+ qb = qb.limit(limit)
+ }
+ if (offset) {
+ qb = qb.offset(offset)
+ }
+ }).fetchAll()
}
db.getCommentCounts = function(ids){
return knex.column('thread').count('* as count').select().from('comments').where('thread', 'in', ids).groupBy('thread')
diff --git a/lib/index.js b/lib/index.js
index f987077..51a8e07 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -83,9 +83,11 @@ site.route = function(){
bucky.ensureCommentCountsForThreads,
bucky.ensureFileCountsForThreads,
bucky.ensureFileSizeForThreads,
+ bucky.ensureHootbox,
function(req, res){
res.json({
threads: res.threads,
+ hootbox: res.hootbox,
})
}
)