Nesting of comments in view, disabling comment form display button on button click

This commit is contained in:
Nathan Leniz
2015-03-07 01:57:09 +09:00
parent 53598a8e6f
commit 6910ed0aea
6 changed files with 168 additions and 94 deletions

View File

@@ -183,28 +183,53 @@ exports.commentSubmit = function(req, res, next) {
rank: 0,
upvotes: 0,
author: data.author,
comments: []
comments: [],
topLevel: true
});
commentSave(comment, Story, res);
};
exports.commentOnCommentSubmit = function(req, res, next) {
var idToFind = req.params.id;
debug('idToFind', idToFind);
var data = req.body.data;
var comment = new Comment({
associatedPost: data.associatedPost,
body: data.body,
rank: 0,
upvotes: 0,
author: data.author,
comments: [],
topLevel: false
});
commentSave(comment, Comment, res);
};
function commentSave(comment, Context, res) {
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);
});
}
});
try {
Context.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);
});
}
});
} catch (e) {
// delete comment
return res.status(500);
}
});
};
}