diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-09-03 18:31:54 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-09-03 18:31:54 -0400 |
| commit | df4892fb2b7abdbdc59ae7f9a7048b3fee1f9a07 (patch) | |
| tree | 02e61e3e40caa79de43e4d19ecf25c0c1c7fb304 /lib/bucky.js | |
| parent | c4f8d3508367de71f708825ccba48096f3490f1f (diff) | |
starting to write apis
Diffstat (limited to 'lib/bucky.js')
| -rw-r--r-- | lib/bucky.js | 46 |
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 |
