Comment submission now works on main story, need to refresh page after submission to display new comment

This commit is contained in:
Nathan Leniz
2015-03-06 06:08:40 +09:00
parent 8552a06ac6
commit 046a209637
3 changed files with 66 additions and 10 deletions

View File

@@ -100,16 +100,6 @@ exports.comments = function(req, res, next) {
});
};
/*
author: {},
comments: {
type: Array,
default: []
},
image:
*/
exports.storySubmission = function(req, res, next) {
var data = req.body.data;
var storyLink = data.headline
@@ -147,3 +137,37 @@ exports.storySubmission = function(req, res, next) {
}));
});
};
exports.commentSubmit = function(req, res, next) {
var data = req.body.data;
var comment = new Comment({
associatedPost: data.associatedPost,
body: data.body,
rank: 0,
upvotes: 0,
author: data.author,
comments: []
});
comment.save(function(err, data) {
if (err) {
return res.status(500);
}
debug('this is data from save', data);
Story.find({'_id': comment.associatedPost}, function(err, associatedStory) {
if (err) {
return res.status(500);
}
associatedStory = associatedStory.pop();
if (associatedStory) {
associatedStory.comments.push(data._id);
associatedStory.save(function(err, data) {
if (err) {
res.status(500);
}
res.send(true);
});
}
});
});
};