Commit c09508c9 authored by 陈家荣's avatar 陈家荣

修改获取文章的接口

parent c9834909
......@@ -107,6 +107,9 @@ 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) {
......@@ -128,22 +131,36 @@ router.get('/thread/:tid/get', function(req, res, next) {
callback(null, results);
}
});
},
function(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[0].from && results[2] && 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));
}
......@@ -290,6 +307,7 @@ 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,
......@@ -322,23 +340,44 @@ 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.getAllThreadByNickName(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));
}
}
});
}
});
......@@ -375,7 +414,9 @@ router.get('/thread/:tid/comment/list', function(req, res, next) {
}else{
forumCommentService.getCommentParent(e._id,function(err,p_comment){
var comment = e.toObject();
comment.floor = p_comment.floor;
if(p_comment){
comment.floor = p_comment.floor;
}
cb(null,comment);
});
}
......
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