summaryrefslogtreecommitdiff
path: root/bucky/app/bucky.js
diff options
context:
space:
mode:
Diffstat (limited to 'bucky/app/bucky.js')
-rw-r--r--bucky/app/bucky.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js
index 76c543a..2a362b5 100644
--- a/bucky/app/bucky.js
+++ b/bucky/app/bucky.js
@@ -312,6 +312,46 @@ var bucky = module.exports = {
next()
})
},
+ ensureThreadsForUser: function (req, res, next){
+ var username = res.user.username
+ var limit = parseInt(req.params.limit) || 10
+ var offset = parseInt(req.params.offset) || 0
+ if (! username) {
+ res.sendStatus(404)
+ }
+ db.getThreadsForUser(username, limit, offset).then(function(threads){
+ res.threads = threads
+ res.threads_ids = res.threads.pluck("id").sort()
+ res.keywords = _.uniq(res.threads.pluck("keyword"))
+ next()
+ })
+ },
+ ensureTopThreadsForUser: function (req, res, next){
+ var username = res.user.username
+ var limit = parseInt(req.params.limit) || 10
+ var offset = parseInt(req.params.offset) || 0
+ if (! username) {
+ res.sendStatus(404)
+ }
+ db.getTopThreadsForUser(username, limit, offset).then(function(top_threads){
+ res.topThreads = top_threads
+ res.topThreads_ids = res.topThreads.pluck("id").sort()
+ res.topKeywords = _.uniq(res.topThreads.pluck("keyword"))
+ next()
+ })
+ },
+ ensureCommentsForUser: function (req, res, next){
+ db.getCommentsForUser(res.user.username).then(function(comments){
+ res.comments = comments || []
+ next()
+ })
+ },
+ ensureFilesForUser: function (req, res, next){
+ db.getFilesForUser(res.user.username).then(function(files){
+ res.files = files || []
+ next()
+ })
+ },
createKeyword: function (req, res, next){
if (! req.body.keyword || ! req.body.keyword.length) {
res.json({ error: "no keyword" })