Commit 21b08a66 authored by 邓军's avatar 邓军

Merge branch 'development' of git.wxpai.cn:scrmgroup/pisns-forum-api into development

parents 021f8437 ea7c891e
...@@ -259,13 +259,13 @@ router.get('/thread/:tid/comment/list', function(req, res, next) { ...@@ -259,13 +259,13 @@ router.get('/thread/:tid/comment/list', function(req, res, next) {
} }
}); });
// 更新评论 // 更新评论状态
router.post('/thread/comment/update/:cid',function(req,res,next){ router.post('/thread/comment/update/:cid',function(req,res,next){
var cid = req.params.cid || null; var cid = req.params.cid || null;
var status = req.body.status; var status = req.body.status;
if(cid){ if(cid){
forumCommentService.updateCommentById(cid, status, function(err,result){ forumCommentService.updateCommentStatusById(cid, status, function(err,result){
if(err){ if(err){
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
}else{ }else{
...@@ -278,6 +278,35 @@ router.post('/thread/comment/update/:cid',function(req,res,next){ ...@@ -278,6 +278,35 @@ router.post('/thread/comment/update/:cid',function(req,res,next){
}); });
// 更新回复评论
router.post('/thread/comment/update/:cid/comments',function(req,res,next){
var cid = req.params.cid || null;
var replayComment_id = req.body.replayComment_id;
// 获取评论的子评论列表
forumCommentService.getCommentById(cid,function(err, result){
if (err) {
console.error(err);
callback(err,null);
} else {
var commentList = result.comments;
console.log('准备插入:' + replayComment_id);
console.log(result._id);
result.comments.push(replayComment_id);
forumCommentService.updateCommentById(cid, result, function(err,result){
if(err){
res.json(returnCode.BUSY);
}else{
res.json(returnCode.SUCCESS);
}
});
}
});
});
//添加评论 //添加评论
router.post('/thread/comment/add', function(req, res, next) { router.post('/thread/comment/add', function(req, res, next) {
var tid = req.body.tid || null; var tid = req.body.tid || null;
...@@ -292,9 +321,12 @@ router.post('/thread/comment/add', function(req, res, next) { ...@@ -292,9 +321,12 @@ router.post('/thread/comment/add', function(req, res, next) {
if(err){ if(err){
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
}else{ }else{
res.json(returnCode.SUCCESS); var returnData = {
// returnCode.SUCCESS,
comment : result
}
res.json(returnData);
} }
}); });
} }
}); });
\ No newline at end of file
...@@ -687,8 +687,15 @@ router.post('/thread/:tid/comment/:cid/delete', function(req, res, next) { ...@@ -687,8 +687,15 @@ router.post('/thread/:tid/comment/:cid/delete', function(req, res, next) {
//评论列表 //评论列表
router.get('/thread/:tid/comment/list', function(req, res, next) { router.get('/thread/:tid/comment/list', function(req, res, next) {
<<<<<<< HEAD
var tid=req.params.tid || null;
var pageNo = req.query.pageNo || 1;
=======
var tid = req.params.tid || null; var tid = req.params.tid || null;
var pageNo = req.query.pageNo || 1; var pageNo = req.query.pageNo || 1;
>>>>>>> f2a61e4b468be1158deee3015cb171b0bede90e4
var pageSize = req.query.pageSize || 10; var pageSize = req.query.pageSize || 10;
var conditions = { var conditions = {
......
...@@ -50,6 +50,11 @@ var ForumCommentSchema = new Schema({ ...@@ -50,6 +50,11 @@ var ForumCommentSchema = new Schema({
require: true, require: true,
default: 0 default: 0
}, },
status: { //文章状态,1启用,0禁用,2需审核
type: Number,
require: true,
default: 1
},
created: { //评论时间 created: { //评论时间
type: Date, type: Date,
require: true, require: true,
......
'use strict'; 'use strict';
var mongoose = require('mongoose'); var mongoose = require('mongoose');
var ForumComment = mongoose.model('ForumComment'); var ForumComment = mongoose.model('ForumComment');
...@@ -30,18 +32,33 @@ exports.getCommentById=function(cid,callback){ ...@@ -30,18 +32,33 @@ exports.getCommentById=function(cid,callback){
}; };
//根据ID更新评论 //根据ID更新评论
exports.updateCommentStatusById=function(cid,status,callback){
ForumComment.update({ _id: cid}, {"status" : status},null,function(err,result){
if (err) {
console.error(err);
callback(err,null);
} else {
console.log(result);
callback(null,null);
}
});
};
//根据ID更新评论 entity
exports.updateCommentById=function(cid,entity,callback){ exports.updateCommentById=function(cid,entity,callback){
ForumComment.update({ _id: cid}, entity,null,function(err,result){ ForumComment.update({ _id: cid}, entity, null, function(err,result){
if (err) { if (err) {
console.error(err); console.error(err);
callback(err,null); callback(err,null);
} else { } else {
console.log(result);
callback(null,null); callback(null,null);
} }
}); });
}; };
//根据ID更新评论
//根据ID删除评论
exports.deleteCommentById=function(cid,callback){ exports.deleteCommentById=function(cid,callback){
ForumComment.remove({ _id: cid},function(err,result){ ForumComment.remove({ _id: cid},function(err,result){
if (err) { if (err) {
...@@ -74,7 +91,7 @@ exports.getAllComment= function(conditions,pageNo,pageSize,callback) { ...@@ -74,7 +91,7 @@ exports.getAllComment= function(conditions,pageNo,pageSize,callback) {
}else{ }else{
var skip = (pageNo - 1) * pageSize; var skip = (pageNo - 1) * pageSize;
var limit = count - skip > pageSize ? pageSize : (count - skip); var limit = count - skip > pageSize ? pageSize : (count - skip);
console.log("count:" + count);
ForumComment.find(conditions).populate('from').populate('to').limit(limit).skip(skip).sort('-created').exec(function(err, docs) { ForumComment.find(conditions).populate('from').populate('to').limit(limit).skip(skip).sort('-created').exec(function(err, docs) {
if (err) { if (err) {
console.error(err); console.error(err);
......
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