Commit 3e3442e8 authored by 陈家荣's avatar 陈家荣

gggg

parent 3f70ee4e
......@@ -30,7 +30,7 @@ router.post('/thread/create', function(req, res, next) {
var rs = {};
req.body.ent_code = req.session.user.ent_code;
if(!req.body.share){
if (!req.body.share) {
delete req.body.share;
}
var uid = req.session.user.id;
......@@ -117,7 +117,7 @@ router.get('/thread/:tid/get', function(req, res, next) {
if (err) {
res.json(returnCode.BUSY);
} else {
if (results[0].pid) {
forumThreadService.getById(results[0].pid, function(err, parentThread) {
rs.data = results[0];
......@@ -256,8 +256,8 @@ router.get('/threads/list', function(req, res, next) {
console.error(err);
res.json(returnCode.BUSY);
} else {
if (results.items.length>0 &&results.items[0].pid) {
if (results.items.length > 0 && results.items[0].pid) {
forumThreadService.getById(results.items[0].pid, function(err, parentThread) {
res.json(_.assign({
parentThread: parentThread
......@@ -324,10 +324,19 @@ router.post('/thread/comment/update/:cid', function(req, res, next) {
console.error(err);
res.json(returnCode.BUSY);
} else {
result.comment_count -= 1;
// result.comment_count -= 1;
// var commentList = result.comments;
// result.comments = forumThreadService.remove(commentList, cid);
var commentList = result.comments;
result.comments = forumThreadService.remove(commentList, cid);
forumThreadService.updateThreadById(tid, result, function(err, result) {
var comments = forumThreadService.remove(commentList, cid);
forumThreadService.updateThreadById(tid, {
comments: comments,
$inc: {
comment_count: -1
}
}, function(err, result) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
......@@ -354,8 +363,10 @@ router.post('/thread/comment/update/:cid', function(req, res, next) {
res.json(returnCode.BUSY);
} else {
var commentList = result.comments;
result.comments = forumCommentService.remove(commentList, cid);
forumCommentService.updateCommentById(parent_cid, result, function(err, result) {
var comments = forumCommentService.remove(commentList, cid);
forumCommentService.updateCommentById(parent_cid, {
comments: comments
}, function(err, result) {
if (err) {
res.json(returnCode.BUSY);
} else {
......@@ -427,14 +438,19 @@ router.post('/thread/comment/update/:cid/comments', function(req, res, next) {
result.comments.push(replayComment_id);
forumCommentService.updateCommentById(cid, result, function(err, result) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json(returnCode.SUCCESS);
}
});
forumCommentService.updateCommentById(cid, {
$push: {
comments: replayComment_id
}
},
function(err, result) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json(returnCode.SUCCESS);
}
});
}
});
......@@ -538,25 +554,44 @@ router.post('/thread/comment/add', function(req, res, next) {
router.post('/thread/:tid/updateComments', function(req, res, next) {
var tid = req.params.tid || null;
var cid = req.body.cid || null;
// 获取评论的子评论列表
forumThreadService.getById(tid, function(err, result) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
result.comments.push(cid);
result.comment_count += 1;
forumThreadService.updateThreadById(tid, result, function(err, result) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json(returnCode.SUCCESS);
}
});
}
});
forumThreadService.updateThreadById(tid, {
$push: {
comments: cid
},
$inc: {
comment_count: 1
}
},
function(err, result) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json(returnCode.SUCCESS);
}
});
// 获取评论的子评论列表
// forumThreadService.getById(tid, function(err, result) {
// if (err) {
// console.error(err);
// res.json(returnCode.BUSY);
// } else {
// result.comments.push(cid);
// result.comment_count += 1;
// forumThreadService.updateThreadById(tid, result,
// function(err, result) {
// if (err) {
// console.error(err);
// res.json(returnCode.BUSY);
// } else {
// res.json(returnCode.SUCCESS);
// }
// });
// }
// });
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment