Commit 240eb72e authored by 陈家荣's avatar 陈家荣

更新查询推荐帖子接口

parent a1142f4a
...@@ -89,6 +89,49 @@ function handleContent(content) { ...@@ -89,6 +89,49 @@ function handleContent(content) {
return content.trim(); return content.trim();
} }
function findOneAndUpdate(id, entity, callback) {
ForumThread.findOneAndUpdate(id, entity, function(err, doc) {
callback(err, doc);
});
};
//根据发帖者分页查询话题列表
exports.findThread = function(pageNo, pageSize, q, sort, callback) {
then(function(cont) {
ForumThread.find(q).count(cont);
}).then(function(cont, count) {
var skip = (pageNo - 1) * pageSize;
var limit = count - skip > pageSize ? pageSize : (count - skip);
var sortBy = '-created';
if (sort) {
sortBy = sort;
}
ForumThread.find(q).populate('from').populate('info').skip(skip).limit(limit).sort(sortBy).exec(function(err, docs) {
cont(err, count, docs);
});
}).then(function(cont, count, threads) {
var rsJson = {
pageNo:pageNo,
pageSize:pageSize,
total: count,
items: threads
};
callback(null, rsJson);
}).fail(function(cont, err) {
console.error(err);
var rsJson = {
result: false,
err: err
};
callback(err, rsJson);
});
};
//根据发帖者分页查询话题列表 //根据发帖者分页查询话题列表
exports.findThreadByPage = function(pageNo, pageSize, q, callback) { exports.findThreadByPage = function(pageNo, pageSize, q, callback) {
then(function(cont) { then(function(cont) {
......
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