From 804fcffa6c1f272d2a724732d440e30d30abfae8 Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Sat, 7 May 2016 10:33:04 +0200 Subject: [PATCH] Subscribers: store post id using the postlookup fn --- core/server/apps/subscribers/lib/router.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/core/server/apps/subscribers/lib/router.js b/core/server/apps/subscribers/lib/router.js index 301677b270..a8492d87cf 100644 --- a/core/server/apps/subscribers/lib/router.js +++ b/core/server/apps/subscribers/lib/router.js @@ -4,7 +4,9 @@ var path = require('path'), // Dirty requires api = require('../../../api'), + errors = require('../../../errors'), templates = require('../../../controllers/frontend/templates'), + postlookup = require('../../../controllers/frontend/post-lookup'), setResponseContext = require('../../../controllers/frontend/context'); function controller(req, res) { @@ -46,8 +48,22 @@ function handleSource(req, res, next) { req.body.subscribed_referrer = req.body.referrer; delete req.body.location; delete req.body.referrer; - // do something here to get post_id - next(); + + postlookup(req.body.subscribed_url) + .then(function (result) { + if (result && result.post) { + req.body.post_id = result.post.id; + } + + next(); + }) + .catch(function (err) { + if (err instanceof errors.NotFoundError) { + return next(); + } + + next(err); + }); } function storeSubscriber(req, res, next) {