summaryrefslogtreecommitdiff
path: root/lib/bucky.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bucky.js')
-rw-r--r--lib/bucky.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/bucky.js b/lib/bucky.js
new file mode 100644
index 0000000..6022bb2
--- /dev/null
+++ b/lib/bucky.js
@@ -0,0 +1,46 @@
+var db = require('./db')
+
+var bucky = module.exports = {
+
+ /* INDEX */
+
+ ensureLatestThreads: function (req, res, next){
+ db.getLatestThreads().then(function(threads){
+ res.threads = threads
+ next()
+ })
+ },
+ ensureCommentCountsForThreads: function (req, res, next){
+ var ids = res.threads.pluck("id")
+ db.getCommentCounts(ids).then(function(counts){
+ console.log(counts)
+ next()
+ })
+ },
+ ensureFileCountsForThreads: function (req, res, next){
+ db.getFileCounts(ids).then(function(counts){
+ next()
+ })
+ },
+
+
+ /* DETAILS */
+
+ ensureThread: function (req, res, next){
+ db.getThread(req.param.id).then(function(thread){
+ if (thread) {
+ res.thread = thread
+ }
+ else {
+ res.sendCode(404)
+ }
+ })
+ },
+ ensureCommentsForThread: function (req, res, next){
+ return db.getCommentsForThread(id).fetch()
+ },
+ ensureFilesForThread: function (req, res, next){
+ return db.getFilesForThread(id).fetch()
+ },
+
+} \ No newline at end of file