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

修改获取文章的接口

parent c9834909
...@@ -107,6 +107,9 @@ router.post('/thread/create', function(req, res, next) { ...@@ -107,6 +107,9 @@ router.post('/thread/create', function(req, res, next) {
//获取目标论坛文章 //获取目标论坛文章
router.get('/thread/:tid/get', 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 tid = req.params.tid || null;
var rs = {}; var rs = {};
if (tid) { if (tid) {
...@@ -128,22 +131,36 @@ router.get('/thread/:tid/get', function(req, res, next) { ...@@ -128,22 +131,36 @@ router.get('/thread/:tid/get', function(req, res, next) {
callback(null, results); callback(null, results);
} }
}); });
},
function(callback) {
forumUserService.getUserByUid(uid, function(err, results) {
if (err) {
callback(err, null);
} else {
callback(null, results);
}
});
} }
], function(err, results) { ], function(err, results) {
if (err) { if (err) {
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
} else { } 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) { if (results[0].pid) {
forumThreadService.getById(results[0].pid, function(err, parentThread) { forumThreadService.getById(results[0].pid, function(err, parentThread) {
rs.data = results[0]; rs.data = results[0];
rs.tagList = results[1]; rs.tagList = results[1];
rs.parentThread = parentThread; rs.parentThread = parentThread;
rs.isSameAuthor = isSameAuthor;
res.json(_.assign(rs, returnCode.SUCCESS)); res.json(_.assign(rs, returnCode.SUCCESS));
}); });
} else { } else {
rs.data = results[0]; rs.data = results[0];
rs.tagList = results[1]; rs.tagList = results[1];
rs.isSameAuthor = isSameAuthor;
res.json(_.assign(rs, returnCode.SUCCESS)); res.json(_.assign(rs, returnCode.SUCCESS));
} }
...@@ -290,6 +307,7 @@ router.get('/threads/list', function(req, res, next) { ...@@ -290,6 +307,7 @@ router.get('/threads/list', function(req, res, next) {
var content = req.query.content; var content = req.query.content;
var type = req.query.type; var type = req.query.type;
var status = req.query.status; var status = req.query.status;
var nickName = req.query.nickName;
var conditions = { var conditions = {
ent_code: req.session.user.ent_code, ent_code: req.session.user.ent_code,
level: 1, level: 1,
...@@ -322,6 +340,26 @@ router.get('/threads/list', function(req, res, next) { ...@@ -322,6 +340,26 @@ router.get('/threads/list', function(req, res, next) {
if(status){ if(status){
conditions.status = status; conditions.status = status;
} }
//根据发帖人查找文章
if(nickName){
forumThreadService.getAllThreadByNickName(nickName, 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));
}
}
});
}else{
forumThreadService.getAllThreadByFid(conditions, pageNo, pageSize, null, function(err, results) { forumThreadService.getAllThreadByFid(conditions, pageNo, pageSize, null, function(err, results) {
if (err) { if (err) {
console.error(err); console.error(err);
...@@ -339,6 +377,7 @@ router.get('/threads/list', function(req, res, next) { ...@@ -339,6 +377,7 @@ router.get('/threads/list', function(req, res, next) {
} }
} }
}); });
}
}); });
...@@ -375,7 +414,9 @@ router.get('/thread/:tid/comment/list', function(req, res, next) { ...@@ -375,7 +414,9 @@ router.get('/thread/:tid/comment/list', function(req, res, next) {
}else{ }else{
forumCommentService.getCommentParent(e._id,function(err,p_comment){ forumCommentService.getCommentParent(e._id,function(err,p_comment){
var comment = e.toObject(); var comment = e.toObject();
if(p_comment){
comment.floor = p_comment.floor; comment.floor = p_comment.floor;
}
cb(null,comment); 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