Skip to content

Commit

Permalink
Fixed issue where the post editing controller was placed in the wrong…
Browse files Browse the repository at this point in the history
… router
  • Loading branch information
julianlam committed Oct 29, 2015
1 parent fbdb6f9 commit ea3284b
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions routes/v1/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,6 @@ module.exports = function(middleware) {
Topics.post(payload, function(err, data) {
return errorHandler.handle(err, res, data);
});
})
.put(apiMiddleware.requireUser, function(req, res) {
if (!utils.checkRequired(['pid', 'content'], req, res)) {
return false;
}

var payload = {
uid: req.user.uid,
pid: req.body.pid,
content: req.body.content,
options: {}
};

// Maybe a "set if available" utils method may come in handy
if (req.body.handle) { payload.handle = req.body.handle; }
if (req.body.title) { payload.title = req.body.title; }
if (req.body.topic_thumb) { payload.options.topic_thumb = req.body.topic_thumb; }
if (req.body.tags) { payload.options.tags = req.body.tags; }

Posts.edit(payload, function(err, returnData) {
errorHandler.handle(err, res, returnData);
});
});

app.route('/:tid')
Expand All @@ -76,6 +54,29 @@ module.exports = function(middleware) {
Topics.delete(req.params.tid, function(err) {
errorHandler.handle(err, res);
});
})
.put(apiMiddleware.requireUser, function(req, res) {
if (!utils.checkRequired(['pid', 'content'], req, res)) {
return false;
}

var payload = {
uid: req.user.uid,
pid: req.body.pid,
content: req.body.content,
options: {}
};
console.log(payload);

// Maybe a "set if available" utils method may come in handy
if (req.body.handle) { payload.handle = req.body.handle; }
if (req.body.title) { payload.title = req.body.title; }
if (req.body.topic_thumb) { payload.options.topic_thumb = req.body.topic_thumb; }
if (req.body.tags) { payload.options.tags = req.body.tags; }

Posts.edit(payload, function(err, returnData) {
errorHandler.handle(err, res, returnData);
});
});

app.route('/:tid/follow')
Expand Down

0 comments on commit ea3284b

Please sign in to comment.