Commit 3f70ee4e authored by 刘文胜's avatar 刘文胜

Merge branch 'development' of git.wxpai.cn:scrmgroup/pisns-forum-api into development

parents adc59954 8eb70843
...@@ -30,7 +30,9 @@ router.post('/thread/create', function(req, res, next) { ...@@ -30,7 +30,9 @@ router.post('/thread/create', function(req, res, next) {
var rs = {}; var rs = {};
req.body.ent_code = req.session.user.ent_code; req.body.ent_code = req.session.user.ent_code;
if(!req.body.share){
delete req.body.share;
}
var uid = req.session.user.id; var uid = req.session.user.id;
// var uid='12345'; // var uid='12345';
if (req.body.pid) { if (req.body.pid) {
...@@ -81,7 +83,9 @@ router.post('/thread/create', function(req, res, next) { ...@@ -81,7 +83,9 @@ router.post('/thread/create', function(req, res, next) {
} }
}); });
} }
}); } } });
}
}
}); });
}); });
...@@ -113,9 +117,20 @@ router.get('/thread/:tid/get', function(req, res, next) { ...@@ -113,9 +117,20 @@ router.get('/thread/:tid/get', function(req, res, next) {
if (err) { if (err) {
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
} else { } else {
rs.data = results[0];
rs.tagList = results[1]; if (results[0].pid) {
res.json(_.assign(rs, returnCode.SUCCESS)); forumThreadService.getById(results[0].pid, function(err, parentThread) {
rs.data = results[0];
rs.tagList = results[1];
rs.parentThread = parentThread;
res.json(_.assign(rs, returnCode.SUCCESS));
});
} else {
rs.data = results[0];
rs.tagList = results[1];
res.json(_.assign(rs, returnCode.SUCCESS));
}
} }
}); });
} else { } else {
...@@ -229,7 +244,7 @@ router.get('/threads/list', function(req, res, next) { ...@@ -229,7 +244,7 @@ router.get('/threads/list', function(req, res, next) {
conditions.level = 2; conditions.level = 2;
} }
if(content){ if (content) {
conditions.content = { conditions.content = {
$regex: content, $regex: content,
$options: 'i' $options: 'i'
...@@ -241,7 +256,16 @@ router.get('/threads/list', function(req, res, next) { ...@@ -241,7 +256,16 @@ router.get('/threads/list', function(req, res, next) {
console.error(err); console.error(err);
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
} else { } else {
res.json(_.assign(results, returnCode.SUCCESS));
if (results.items.length>0 &&results.items[0].pid) {
forumThreadService.getById(results.items[0].pid, function(err, parentThread) {
res.json(_.assign({
parentThread: parentThread
}, results, returnCode.SUCCESS));
});
} else {
res.json(_.assign(results, returnCode.SUCCESS));
}
} }
}); });
}); });
...@@ -298,7 +322,7 @@ router.post('/thread/comment/update/:cid', function(req, res, next) { ...@@ -298,7 +322,7 @@ router.post('/thread/comment/update/:cid', function(req, res, next) {
forumThreadService.getById(tid, function(err, result) { forumThreadService.getById(tid, function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); res.json(returnCode.BUSY);
} else { } else {
result.comment_count -= 1; result.comment_count -= 1;
var commentList = result.comments; var commentList = result.comments;
...@@ -306,7 +330,7 @@ router.post('/thread/comment/update/:cid', function(req, res, next) { ...@@ -306,7 +330,7 @@ router.post('/thread/comment/update/:cid', function(req, res, next) {
forumThreadService.updateThreadById(tid, result, function(err, result) { forumThreadService.updateThreadById(tid, result, function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); res.json(returnCode.BUSY);
} else { } else {
res.json(returnCode.SUCCESS); res.json(returnCode.SUCCESS);
} }
...@@ -316,9 +340,9 @@ router.post('/thread/comment/update/:cid', function(req, res, next) { ...@@ -316,9 +340,9 @@ router.post('/thread/comment/update/:cid', function(req, res, next) {
} else { // 删除子评论 } else { // 删除子评论
// 更新文章评论 - 1 // 更新文章评论 - 1
forumThreadService.updateThreadCommentCount(tid, comment_count - 1, function(err, result) { forumThreadService.updateThreadCommentCount(tid, function(err, result) {
if (err) { if (err) {
callback(err, null); res.json(returnCode.BUSY);
} }
}); });
...@@ -327,7 +351,7 @@ router.post('/thread/comment/update/:cid', function(req, res, next) { ...@@ -327,7 +351,7 @@ router.post('/thread/comment/update/:cid', function(req, res, next) {
forumCommentService.getCommentById(parent_cid, function(err, result) { forumCommentService.getCommentById(parent_cid, function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); res.json(returnCode.BUSY);
} else { } else {
var commentList = result.comments; var commentList = result.comments;
result.comments = forumCommentService.remove(commentList, cid); result.comments = forumCommentService.remove(commentList, cid);
...@@ -372,7 +396,14 @@ router.post('/thread/comment/update/:cid/comments', function(req, res, next) { ...@@ -372,7 +396,14 @@ router.post('/thread/comment/update/:cid/comments', function(req, res, next) {
}); });
// 更新评论对象 // 更新评论对象
// result.comment_count+=1; // 回复评论+1 // result.comment_count+=1; // 回复评论+1
forumCommentService.updateCommentById(cid, {$push:{comments:replayComment_id},$inc:{comment_count:1}}, function(err, result) { forumCommentService.updateCommentById(cid, {
$push: {
comments: replayComment_id
},
$inc: {
comment_count: 1
}
}, function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
...@@ -390,15 +421,15 @@ router.post('/thread/comment/update/:cid/comments', function(req, res, next) { ...@@ -390,15 +421,15 @@ router.post('/thread/comment/update/:cid/comments', function(req, res, next) {
forumCommentService.getCommentById(cid, function(err, result) { forumCommentService.getCommentById(cid, function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); res.json(returnCode.BUSY);
} else { } else {
var commentList = result.comments; var commentList = result.comments;
result.comments.push(replayComment_id); result.comments.push(replayComment_id);
forumCommentService.updateCommentById(cid, result, function(err, result) { forumCommentService.updateCommentById(cid, result, function(err, result) {
if (err) { if (err) {
console.error(err);
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
} else { } else {
res.json(returnCode.SUCCESS); res.json(returnCode.SUCCESS);
...@@ -455,6 +486,7 @@ router.post('/thread/comment/add', function(req, res, next) { ...@@ -455,6 +486,7 @@ router.post('/thread/comment/add', function(req, res, next) {
}; };
forumUserService.createUser(userentity, function(err, doc) { forumUserService.createUser(userentity, function(err, doc) {
if (err) { if (err) {
console.log(err);
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
} else { } else {
entity.from = doc._id; entity.from = doc._id;
...@@ -480,7 +512,7 @@ router.post('/thread/comment/add', function(req, res, next) { ...@@ -480,7 +512,7 @@ router.post('/thread/comment/add', function(req, res, next) {
res.json(returnCode.WRONG_PARAM); res.json(returnCode.WRONG_PARAM);
} }
// 测试环境 // 测试环境
// entity.from = '55015675868b65a028187c49'; // entity.from = '55015675868b65a028187c49';
...@@ -510,7 +542,7 @@ router.post('/thread/:tid/updateComments', function(req, res, next) { ...@@ -510,7 +542,7 @@ router.post('/thread/:tid/updateComments', function(req, res, next) {
forumThreadService.getById(tid, function(err, result) { forumThreadService.getById(tid, function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); res.json(returnCode.BUSY);
} else { } else {
result.comments.push(cid); result.comments.push(cid);
result.comment_count += 1; result.comment_count += 1;
...@@ -518,7 +550,7 @@ router.post('/thread/:tid/updateComments', function(req, res, next) { ...@@ -518,7 +550,7 @@ router.post('/thread/:tid/updateComments', function(req, res, next) {
forumThreadService.updateThreadById(tid, result, function(err, result) { forumThreadService.updateThreadById(tid, result, function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); res.json(returnCode.BUSY);
} else { } else {
res.json(returnCode.SUCCESS); res.json(returnCode.SUCCESS);
} }
......
...@@ -674,12 +674,17 @@ exports.updateThreadCommentCountInc = function(threadId, callback) { ...@@ -674,12 +674,17 @@ exports.updateThreadCommentCountInc = function(threadId, callback) {
}; };
//更新文章评论数 //更新文章评论数
exports.updateThreadCommentCount = function(threadId, comment_count, callback) { exports.updateThreadCommentCount = function(threadId, callback) {
ForumThread.update({ ForumThread.update({
_id: threadId _id: threadId
}, { }, {
'comment_count': comment_count $inc: {
}, null, comment_count: -1
}
}, {
w: 1,
safe: true
},
function(err, result) { function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
......
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