From 3aad9b4b70921e9be670560f42f00dcd448e27bb Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 11 Dec 2017 10:34:34 +0100 Subject: bumpViewCount and revisions --- bucky/app/bucky.js | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'bucky/app/bucky.js') diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js index 8b829da..e7455ad 100644 --- a/bucky/app/bucky.js +++ b/bucky/app/bucky.js @@ -94,7 +94,7 @@ var bucky = module.exports = { next() }) }, - + /* DETAILS */ ensureThread: function (req, res, next){ @@ -112,6 +112,24 @@ var bucky = module.exports = { } }) }, + ensureCommentThread: function (req, res, next){ + if (! res.comment) { + return res.sendStatus(404) + } + var id = res.comment.get('thread') + if (! id) { + return res.sendStatus(404) + } + db.getThread(id).then(function(thread){ + if (thread) { + res.thread = thread + next() + } + else { + res.sendStatus(404) + } + }) + }, ensureKeywordForThread: function (req, res, next){ var keyword = res.thread.get('keyword') if (! keyword) return next() @@ -132,7 +150,16 @@ var bucky = module.exports = { next() }) }, - + bumpViewCount: function(req, res, next) { + res.thread.set('viewed', res.thread.get('viewed') + 1) + res.thread.save().then( () => next() ) + }, + bumpThreadRevisions: function (req, res, next){ + res.thread.set('revision', res.thread.get('revision')+1) + res.thread.set('lastmodified', util.now()) + res.thread.save().then( () => next() ) + }, + /* KEYWORDS */ ensureKeyword: function (req, res, next){ -- cgit v1.2.3-70-g09d2