Commit 572d8481 authored by 张淼's avatar 张淼

1

parent 6bec50cc
...@@ -478,7 +478,7 @@ router.post('/thread/:tid/comment/:cid/create', function(req, res, next) { ...@@ -478,7 +478,7 @@ router.post('/thread/:tid/comment/:cid/create', function(req, res, next) {
level:'2' level:'2'
}; };
//4.创建文章评论 //4.创建文章评论
forumCommentService.createComment(entity,function(err,result){ forumCommentService.createComment(entity,function(err,newComment){
if(err){ if(err){
callback(err,null); callback(err,null);
}else{ }else{
...@@ -487,12 +487,12 @@ router.post('/thread/:tid/comment/:cid/create', function(req, res, next) { ...@@ -487,12 +487,12 @@ router.post('/thread/:tid/comment/:cid/create', function(req, res, next) {
if(comments && comments.length>0){ if(comments && comments.length>0){
array=comments; array=comments;
} }
array.push(result._id); array.push(newComment._id);
forumCommentService.updateCommentById(cid,{comments:array},function(err,result){ forumCommentService.updateCommentById(cid,{comments:array},function(err,result){
if(err){ if(err){
callback(err,null); callback(err,null);
}else{ }else{
callback(null,null); callback(null,newComment);
} }
}); });
} }
...@@ -513,7 +513,16 @@ router.post('/thread/:tid/comment/:cid/create', function(req, res, next) { ...@@ -513,7 +513,16 @@ router.post('/thread/:tid/comment/:cid/create', function(req, res, next) {
console.error(err); console.error(err);
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
}else{ }else{
res.json(returnCode.SUCCESS); ForumComment.populate(results[0], {path:'from to', select:'uid nickName icon comments'} , function(err, c){
if(err){
res.json(returnCode.BUSY);
}else{
var rs={};
rs.data=results[0];
res.json(_.assign(rs,returnCode.SUCCESS));
}
});
// res.json(returnCode.SUCCESS);
} }
}); });
} }
...@@ -574,10 +583,10 @@ router.post('/thread/:tid/comment/:cid/delete', function(req, res, next) { ...@@ -574,10 +583,10 @@ router.post('/thread/:tid/comment/:cid/delete', function(req, res, next) {
}); });
//评论列表 //评论列表
router.post('/thread/:tid/comment/list', function(req, res, next) { router.get('/thread/:tid/comment/list', function(req, res, next) {
var tid=req.params.tid || null; var tid=req.params.tid || null;
var pageNo = req.query.pageNo || 1; var pageNo = req.query.pageNo || 1;
var pageSize = req.query.pageSize || 5; var pageSize = req.query.pageSize || 10;
var conditions={ var conditions={
thread:tid, thread:tid,
......
...@@ -58,7 +58,7 @@ exports.getThreadById=function(tid,callback){ ...@@ -58,7 +58,7 @@ exports.getThreadById=function(tid,callback){
level:'1' level:'1'
}; };
//获取最新5条评论 //获取最新5条评论
forumCommentService.getAllComment(conditions,1,5,function(err,results){ forumCommentService.getAllComment(conditions,1,10,function(err,results){
if(err){ if(err){
console.log(err); console.log(err);
cb(err,null); cb(err,null);
...@@ -207,7 +207,7 @@ exports.getAllThreadByFid= function(conditions,pageNo,pageSize,callback) { ...@@ -207,7 +207,7 @@ exports.getAllThreadByFid= function(conditions,pageNo,pageSize,callback) {
var skip = (pageNo - 1) * pageSize; var skip = (pageNo - 1) * pageSize;
var limit = count - skip > pageSize ? pageSize : (count - skip); var limit = count - skip > pageSize ? pageSize : (count - skip);
ForumThread.find(conditions).populate('from').populate('info').populate({path:'tag'}).populate({path:'comments',options:{limit:5,sort:'-created'}, select:'from to created content'}).limit(limit).skip(skip).sort('-top created').exec(function(err, docs) { ForumThread.find(conditions).populate('from').populate('info').populate({path:'tag'}).populate({path:'comments',options:{limit:5,sort:'-created'}, select:'from to created content'}).limit(limit).skip(skip).sort('-top -created').exec(function(err, docs) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err,null); callback(err,null);
......
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