From df4892fb2b7abdbdc59ae7f9a7048b3fee1f9a07 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 3 Sep 2015 18:31:54 -0400 Subject: starting to write apis --- lib/bucky.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 lib/bucky.js (limited to 'lib/bucky.js') 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 -- cgit v1.2.3-70-g09d2