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

删除板块时API检查是否有有效的帖子

parent e93dc73f
...@@ -5,7 +5,8 @@ var express = require('express'), ...@@ -5,7 +5,8 @@ var express = require('express'),
_ = require('lodash'), _ = require('lodash'),
moment = require('moment'), moment = require('moment'),
nodeExcel = require('excel-export'), nodeExcel = require('excel-export'),
then = require('thenjs'); then = require('thenjs'),
async = require('async');
var mongoose = require('mongoose'); var mongoose = require('mongoose');
var ForumInfo = mongoose.model('ForumInfo'); var ForumInfo = mongoose.model('ForumInfo');
...@@ -144,20 +145,58 @@ router.post('/info/:fid/update', function(req, res, next) { ...@@ -144,20 +145,58 @@ router.post('/info/:fid/update', function(req, res, next) {
} }
}); });
//删除目标论坛板块
//删除目标论坛板块 //删除目标论坛板块
router.post('/info/:fid/delete', function(req, res, next) { router.post('/info/:fid/delete', function(req, res, next) {
var fid=req.params.fid; var fid=req.params.fid;
if(fid){ var ent_code = req.session.user.ent_code;
forumInfoService.deleteInfoById(fid,function(err,result){ if(fid){
if(err){ async.waterfall([
res.json(returnCode.BUSY); function(callback) {
}else{ var today = new Date();
res.json(returnCode.SUCCESS); var conditions = {
} ent_code: ent_code,
}); info: fid,
}else{ level: 1,
res.json(returnCode.WRONG_PARAM); status: 1,
} $or: [{
isEvent: {
$ne:1
}
}, {
isEvent: 1,
'event.eventStartTime' : {$lte : today}
}]
};
//统计板块有效的文章
forumThreadService.countThread(conditions, function(err, count) {
if (err) {
callback(err, null);
} else {
callback(null, count);
}
});
}
], function(err, count) {
if (err) {
res.json(returnCode.BUSY);
} else {
if(count > 0){
res.json(returnCode.CAN_NOT_DELETE_INFO);
}else{
forumInfoService.deleteInfoById(fid,function(err,result){
if(err){
res.json(returnCode.BUSY);
}else{
res.json(returnCode.SUCCESS);
}
});
}
}
});
}else{
res.json(returnCode.WRONG_PARAM);
}
}); });
/** /**
......
...@@ -1635,3 +1635,13 @@ exports.getThreadWithNotPopulateComment = function(conditions, pageNo, pageSize, ...@@ -1635,3 +1635,13 @@ exports.getThreadWithNotPopulateComment = function(conditions, pageNo, pageSize,
}; };
exports.countThread = function (conditions, callback) {
ForumThread.count(conditions, function(err, count) {
if (err) {
console.error(err);
callback(err, null);
} else {
callback(null, count);
}
});
}
\ No newline at end of file
...@@ -46,6 +46,10 @@ module.exports = { ...@@ -46,6 +46,10 @@ module.exports = {
errorcode: 10008, errorcode: 10008,
errormsg: '内容超出限制' errormsg: '内容超出限制'
}, },
CAN_NOT_DELETE_INFO: {
errorcode: 10009,
errormsg: '不能删除,请先转移版块下的帖子'
},
UNCHECK_ERROR:function(msg){ UNCHECK_ERROR:function(msg){
return { return {
errorcode:9999, errorcode:9999,
......
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