Commit 8aa1e3d3 authored by 刘文胜's avatar 刘文胜

1111

parent 465aa545
......@@ -421,6 +421,7 @@ router.get('/info/myComments', function(req, res, next) {
var id=user.getMobileUser(req);
var conditions = {
ent_code: req.session.user.ent_code,
status:1,
$or:[{from: id},{to: id}]
};
forumCommentService.getMyComment(conditions, pageNo, pageSize, function(err, results) {
......
......@@ -303,6 +303,25 @@ var countMyComment = function(conditions,callback) {
}
});
};
function populateParentComment(doc, callback){
if (doc && doc._id && doc.level === 2) {
ForumComment.findOne({comments: { $elemMatch : doc._id },status:1}).exec(function(err,c){
if (err) {
console.error(err);
callback(null, null);
} else{
if(c){
callback(null ,c);
}else{
callback(null);
}
}
});
} else{
callback(null, null);
}
}
//我的评论
exports.getMyComment = function(conditions,pageNo,pageSize,callback){
countMyComment(conditions,function(err,count){
......@@ -313,7 +332,10 @@ exports.getMyComment = function(conditions,pageNo,pageSize,callback){
var limit = count - skip > pageSize ? pageSize : (count - skip);
ForumComment.find(conditions)
.populate('thread').populate('from').populate('to').limit(limit).skip(skip).sort('-created').exec(function(err, docs) {
.populate({
path: 'thread',
select: '_id content title type level tag'
}).populate({path:'from to', select:'uid nickName icon'}).limit(limit).skip(skip).sort('-created').exec(function(err, docs) {
if (err) {
console.error(err);
callback(err,null);
......@@ -324,8 +346,36 @@ exports.getMyComment = function(conditions,pageNo,pageSize,callback){
obj.pageSize=pageSize;
obj.items=docs;
if (docs && docs.length > 0) {
var asyncTasks = [];
docs.forEach(function(doc){
asyncTasks.push(function(callback) {
populateParentComment(doc, function(err,c){
if(err){
callback(err,null);
}else{
var newobj = doc.toObject();
newobj.parent = c;
delete newobj.comments;
callback(null,newobj);
}
});
});
});
async.parallel(asyncTasks, function(err, results) {
if (err) {
console.log(err);
callback(null, null);
} else {
obj.items=results;
callback(null,obj);
}
});
}else{
callback(null,obj);
}
}
});
}
});
......
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