diff options
Diffstat (limited to 'lib/bucky.js')
| -rw-r--r-- | lib/bucky.js | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/lib/bucky.js b/lib/bucky.js index 9ec28f4..ef822c4 100644 --- a/lib/bucky.js +++ b/lib/bucky.js @@ -7,43 +7,70 @@ var bucky = module.exports = { ensureLatestThreads: function (req, res, next){ db.getLatestThreads().then(function(threads){ res.threads = threads + res.threads_ids = res.threads.pluck("id").sort() next() }) }, ensureCommentCountsForThreads: function (req, res, next){ - var ids = res.threads.pluck("id") - db.getCommentCounts(ids).then(function(counts){ + db.getCommentCounts(res.threads_ids).then(function(counts){ var lookup = {} - console.log(counts) - counts.forEach(function(count){ + counts.forEach(function(c,i){ + res.threads.at(i).set("comment_count", c.count) }) next() }) }, ensureFileCountsForThreads: function (req, res, next){ - db.getFileCounts(ids).then(function(counts){ + db.getFileCounts(res.threads_ids).then(function(counts){ + var lookup = {} + counts.forEach(function(c,i){ + res.threads.at(i).set("file_count", c.count) + }) next() }) }, - - + ensureFileSizeForThreads: function (req, res, next){ + db.getFileSizes(res.threads_ids).then(function(sizes){ + var lookup = {} + sizes.forEach(function(c,i){ + res.threads.at(i).set("file_size", c.size) + }) + next() + }) + }, + /* DETAILS */ ensureThread: function (req, res, next){ db.getThread(req.param.id).then(function(thread){ if (thread) { res.thread = thread + next() } else { res.sendCode(404) } }) }, + ensureKeywordForThread: function (req, res, next){ + var keyword = res.thread.get('keyword') + if (! keyword) return next() + db.getKeyword(keyword).then(function(keyword){ + res.keyword = keyword + next() + }) + }, ensureCommentsForThread: function (req, res, next){ - return db.getCommentsForThread(id).fetch() + db.getCommentsForThread(id).then(function(comments){ + res.comments = comments + next() + }) }, ensureFilesForThread: function (req, res, next){ - return db.getFilesForThread(id).fetch() + db.getCommentsForThread(id).then(function(files){ + res.files = files + next() + }) }, }
\ No newline at end of file |
