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

子文章管理

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