Commit 7059dc89 authored by 邓军's avatar 邓军

子文章管理

parent 114142af
......@@ -10,14 +10,14 @@ var async = require('async');
var then = require('thenjs');
//查询帖子
exports.findThreadByPage = function(pageNo,pageSize,q,callback) {
exports.findThreadByPage = function(pageNo, pageSize, q, callback) {
then(function(cont) {
ForumThread.find(q).populate('from').count(cont);
}).then(function(cont, count) {
var skip = (pageNo - 1) * pageSize;
var limit = count - skip > pageSize ? pageSize : (count - skip);
ForumThread.find(q).skip(skip).limit(limit).sort('-created').exec(function(err, docs) {
cont(err, count, docs);
});
}).then(function(cont, count, threads) {
......@@ -26,28 +26,28 @@ exports.findThreadByPage = function(pageNo,pageSize,q,callback) {
total: count,
datas: threads
};
callback(null,rsJson);
callback(null, rsJson);
}).fail(function(cont, err) {
console.error(err);
var rsJson = {
result: false,
err: err
};
callback(err,rsJson);
callback(err, rsJson);
});
};
//查询评论
exports.findCommentByPage = function(pageNo,pageSize,q,callback) {
exports.findCommentByPage = function(pageNo, pageSize, q, callback) {
then(function(cont) {
ForumComment.find(q).populate('from').count(cont);
}).then(function(cont, count) {
var skip = (pageNo - 1) * pageSize;
var limit = count - skip > pageSize ? pageSize : (count - skip);
ForumComment.find(q).skip(skip).limit(limit).sort('-created').populate('from').exec(function(err, docs) {
cont(err, count, docs);
});
}).then(function(cont, count, threads) {
......@@ -56,15 +56,15 @@ exports.findCommentByPage = function(pageNo,pageSize,q,callback) {
total: count,
datas: threads
};
callback(null,rsJson);
callback(null, rsJson);
}).fail(function(cont, err) {
console.error(err);
var rsJson = {
result: false,
err: err
};
callback(err,rsJson);
callback(err, rsJson);
});
};
......@@ -254,8 +254,13 @@ exports.getThreadById = function(tid, callback) {
//根据ID更新文章
exports.updateThreadById = function(tid, entity, callback) {
var shareEntity = entity.share;
entity.share = entity.share._id;
if (entity.share._id) {
entity.share = entity.share._id;
}else{
entity.share = '';
}
if (entity.share) {
ForumThread.update({
_id: tid
}, entity, null, function(err, result) {
......@@ -265,12 +270,12 @@ exports.updateThreadById = function(tid, entity, callback) {
} else {
ForumShare.update({
_id: shareEntity._id
}, shareEntity, null, function(err, result) {
}, shareEntity, null, function(err, se) {
if (err) {
console.error(err);
callback(err, null);
} else {
callback(null, null);
callback(null, entity);
}
});
......@@ -291,7 +296,7 @@ exports.updateThreadById = function(tid, entity, callback) {
console.error(err);
callback(err, null);
} else {
callback(null, null);
callback(null, entity);
}
});
......@@ -305,7 +310,7 @@ exports.updateThreadById = function(tid, entity, callback) {
console.error(err);
callback(err, null);
} else {
callback(null, null);
callback(null, entity);
}
});
......
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