Commit 80968d60 authored by 陈志良's avatar 陈志良

微社区

parent 9ea176ea
...@@ -336,11 +336,11 @@ router.post('/thread/comment/update/:cid', function(req, res, next) { ...@@ -336,11 +336,11 @@ router.post('/thread/comment/update/:cid', function(req, res, next) {
// var commentList = result.comments; // var commentList = result.comments;
// result.comments = forumThreadService.remove(commentList, cid); // result.comments = forumThreadService.remove(commentList, cid);
// var commentList = result.comments; var commentList = result.comments;
// var comments = forumThreadService.remove(commentList, cid); var comments = forumThreadService.remove(commentList, cid);
forumThreadService.updateThreadById(tid, { forumThreadService.updateThreadById(tid, {
"$pull" : { "comments" : { "_id" : cid}}, comments:comments,
$inc: { comment_count: -1 } $inc: { comment_count: -1 }
}, function(err, result) { }, function(err, result) {
if (err) { if (err) {
...@@ -371,12 +371,7 @@ router.post('/thread/comment/update/:cid', function(req, res, next) { ...@@ -371,12 +371,7 @@ router.post('/thread/comment/update/:cid', function(req, res, next) {
var commentList = result.comments; var commentList = result.comments;
var comments = forumCommentService.remove(commentList, cid); var comments = forumCommentService.remove(commentList, cid);
forumCommentService.updateCommentById(parent_cid, { forumCommentService.updateCommentById(parent_cid, {
"$pull": { comments:comments
"comments": {
"_id": cid
}
}
}, function(err, result) { }, function(err, result) {
if (err) { if (err) {
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
......
...@@ -698,7 +698,8 @@ router.get('/thread/:tid/comment/list', function(req, res, next) { ...@@ -698,7 +698,8 @@ router.get('/thread/:tid/comment/list', function(req, res, next) {
var conditions = { var conditions = {
ent_code: req.session.user.ent_code, ent_code: req.session.user.ent_code,
thread: tid, thread: tid,
level: '1' level: '1',
status:1
}; };
if (tid) { if (tid) {
......
...@@ -142,12 +142,16 @@ function populateComment(doc, callback){ ...@@ -142,12 +142,16 @@ function populateComment(doc, callback){
var asyncTasks = []; var asyncTasks = [];
doc.comments.forEach(function(comment){ doc.comments.forEach(function(comment){
asyncTasks.push(function(callback) { asyncTasks.push(function(callback) {
ForumComment.findOne({_id: comment}).populate({path:'from to', select:'uid nickName icon'}).exec(function(err,c){ ForumComment.findOne({_id: comment,status:1}).populate({path:'from to', select:'uid nickName icon'}).exec(function(err,c){
if (err) { if (err) {
console.error(err); console.error(err);
callback(null, null); callback(null, null);
} else{ } else{
callback(null ,c); if(c){
callback(null ,c);
}else{
callback(null);
}
} }
}); });
}); });
...@@ -157,8 +161,13 @@ function populateComment(doc, callback){ ...@@ -157,8 +161,13 @@ function populateComment(doc, callback){
console.log(err); console.log(err);
callback(null, null); callback(null, null);
} else { } else {
// console.log(results); var comments = [];
callback(null, results); for(var i=0;i<results.length;i+=1){
if(results[i]){
comments.push(results[i]);
}
}
callback(null,comments);
} }
}); });
......
...@@ -129,25 +129,20 @@ exports.getThreadById = function(tid, callback) { ...@@ -129,25 +129,20 @@ exports.getThreadById = function(tid, callback) {
var conditions = { var conditions = {
_id: tid _id: tid
}; };
ForumThread.find(conditions).populate('from').populate('info').populate('share').exec(function(err, docs) { ForumThread.findOne(conditions).populate('from').populate('info').populate('share').exec(function(err, doc) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); callback(err, null);
} else { } else {
var thread = {}; cb(null, doc);
if (docs && docs.length > 0) {
thread = docs[0];
cb(null, thread);
} else {
cb(null, thread);
}
} }
}); });
}, },
function(cb) { function(cb) {
var conditions = { var conditions = {
thread: tid, thread: tid,
level: '1' level: '1',
status:1
}; };
//获取最新10条评论 //获取最新10条评论
forumCommentService.getAllComment(conditions, 1, 10, function(err, results) { forumCommentService.getAllComment(conditions, 1, 10, function(err, results) {
...@@ -163,7 +158,8 @@ exports.getThreadById = function(tid, callback) { ...@@ -163,7 +158,8 @@ exports.getThreadById = function(tid, callback) {
//获取话题子文章列表 //获取话题子文章列表
var conditions = { var conditions = {
pid: tid, pid: tid,
type: 2 type: 2,
status:1
}; };
getAllThreadByFidHelp(conditions, 1, 10, null, function(err, threads) { getAllThreadByFidHelp(conditions, 1, 10, null, function(err, threads) {
if (err) { if (err) {
...@@ -180,6 +176,7 @@ exports.getThreadById = function(tid, callback) { ...@@ -180,6 +176,7 @@ exports.getThreadById = function(tid, callback) {
var conditions = { var conditions = {
pid: tid, pid: tid,
type: 3, type: 3,
status:1,
images: {$exists: true, $not: {$size: 0}} images: {$exists: true, $not: {$size: 0}}
}; };
getAllThreadByFidHelp(conditions, 1, 10, '-created', function(err, threads) { getAllThreadByFidHelp(conditions, 1, 10, '-created', function(err, threads) {
...@@ -196,6 +193,7 @@ exports.getThreadById = function(tid, callback) { ...@@ -196,6 +193,7 @@ exports.getThreadById = function(tid, callback) {
var conditions = { var conditions = {
pid: tid, pid: tid,
type: 3, type: 3,
status:1,
images: {$exists: true, $not: {$size: 0}} images: {$exists: true, $not: {$size: 0}}
}; };
getAllThreadByFidHelp(conditions, 1, 10, '-praise_count', function(err, threads) { getAllThreadByFidHelp(conditions, 1, 10, '-praise_count', function(err, threads) {
...@@ -487,6 +485,7 @@ function getAllThreadByFidHelp(conditions, pageNo, pageSize, sort, callback) { ...@@ -487,6 +485,7 @@ function getAllThreadByFidHelp(conditions, pageNo, pageSize, sort, callback) {
}).populate({ }).populate({
path: 'comments', path: 'comments',
options: { options: {
where:{status:1},
limit: 5, limit: 5,
sort: '-created' sort: '-created'
}, },
......
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