Commit 857b0774 authored by 陈家荣's avatar 陈家荣

更新了查询文章的方法

parent c8a81d87
......@@ -106,6 +106,7 @@ router.post('/thread/create', function(req, res, next) {
//获取目标论坛文章
router.get('/thread/:tid/get', function(req, res, next) {
var uid = req.session.user.id;
var tid = req.params.tid || null;
var rs = {};
if (tid) {
......@@ -132,22 +133,37 @@ router.get('/thread/:tid/get', function(req, res, next) {
callback(null,[thread]);
}
},
function(thread,callback) {
forumUserService.getUserByUid(uid,function(err, results) {
if (err) {
callback(err, null);
} else {
callback(null, results);
}
});
}
], function(err, results) {
if (err) {
res.json(returnCode.BUSY);
} else {
var isSameAuthor = false;
if(results[0] && results[2] && results[0].from && results[0].from._id.toString() === results[2]._id.toString()){
isSameAuthor = true;
}
if (results[0].pid) {
forumThreadService.getById(results[0].pid, function(err, parentThread) {
rs.data = results[0];
rs.tagList = results[1];
rs.parentThread = parentThread;
rs.isSameAuthor = isSameAuthor;
res.json(_.assign(rs, returnCode.SUCCESS));
});
} else {
rs.data = results[0];
rs.tagList = results[1];
rs.isSameAuthor = isSameAuthor;
res.json(_.assign(rs, returnCode.SUCCESS));
}
......@@ -294,6 +310,8 @@ router.get('/threads/list', function(req, res, next) {
var content = req.query.content;
var type = req.query.type;
var status = req.query.status;
var nickName = req.query.nickName;
var conditions = {
ent_code: req.session.user.ent_code,
level: 1,
......@@ -326,23 +344,46 @@ router.get('/threads/list', function(req, res, next) {
if(status){
conditions.status = status;
}
forumThreadService.getAllThreadByFid(conditions, pageNo, pageSize, null, function(err, results) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
if (pid) {
forumThreadService.getById(pid, function(err, parentThread) {
res.json(_.assign({
parentThread: parentThread
}, results, returnCode.SUCCESS));
});
if(nickName){
forumThreadService.getAllThreadByFidAndNickName(nickName, conditions, pageNo, pageSize, null, function(err, results) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json(_.assign(results, returnCode.SUCCESS));
if (pid) {
forumThreadService.getById(pid, function(err, parentThread) {
res.json(_.assign({
parentThread: parentThread
}, results, returnCode.SUCCESS));
});
} else {
res.json(_.assign(results, returnCode.SUCCESS));
}
}
}
});
});
}else{
forumThreadService.getAllThreadByFid(conditions, pageNo, pageSize, null, function(err, results) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
if (pid) {
forumThreadService.getById(pid, function(err, parentThread) {
res.json(_.assign({
parentThread: parentThread
}, results, returnCode.SUCCESS));
});
} else {
res.json(_.assign(results, returnCode.SUCCESS));
}
}
});
}
});
......
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