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

微社区

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