Commit 646033df authored by 刘文胜's avatar 刘文胜

举报接口修改

parent 440d4a7e
'use strict';
var mongoose = require('mongoose');
var ForumComplaint = mongoose.model('ForumComplaint');
var ForumThread = mongoose.model('ForumThread');
var ForumComment = mongoose.model('ForumComment');
var ForumUserService = require("./forumUserService");
var async=require('async');
......@@ -43,11 +45,46 @@ exports.getForumComplaintPageList=function(condition,pageNo,pageSize,callback){
};
exports.addComplaint = function(complaint,entcode,callback){
if(!!!complaint || !!!complaint.complaintId){
if(!!!complaint || !!!complaint.complaintId || !!!complaint.type){
return callback && callback('bad args');
}
complaint.ent_code = entcode;
async.waterfall([function(cb) {
/*var to =complaint.to;
delete complaint.to;
if(!!!to){
return cb();
}
ForumUserService.getUserById(to,
function(err,result){
if(!!!err && result){
complaint.complaintTo = result;
}
cb();
});*/
var _Model = null;
var type = 0;
try{
type =Number(complaint.type);
}catch(e){}
if(type === 1){
_Model = ForumThread;
}else if(type === 2){
_Model = ForumComment;
}
if(!!!_Model){
return callback && callback('bad args');
}
_Model.findById(complaint.complaintId).populate('from')
.exec(function(err,result){
if(err || !result){//没有对应的文章或评论
return callback && callback(err || '无对应数据');
}
complaint.content = result.content;
complaint.complaintTo = result.from;
cb();
});
},function(cb) {
var from =complaint.from;
delete complaint.from;
if(!!!from){
......@@ -83,20 +120,6 @@ exports.addComplaint = function(complaint,entcode,callback){
});
}
},
function(cb) {
var to =complaint.to;
delete complaint.to;
if(!!!to){
return cb();
}
ForumUserService.getUserById(to,
function(err,result){
if(!!!err && result){
complaint.complaintTo = result;
}
cb();
});
},
function(n, cb) {
var _complaint= new ForumComplaint(complaint);
_complaint.save(function(err, result) {
......
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