我的代码有问题..
如果我使用validate result.length == 0我总是得到错误ID未定义。
如果callback(id) == undefined
并且返回消息,我将如何从此函数获取验证以获取错误。
代码:
型号:
var DAO = require('../lib/database.js');
module.exports = {
deleteduser : function(id,callback){
var User = DAO.executeQuery("delete from ms_customer WHERE id = '" + id + "';", function(rows){
callback(rows[0]);
});
},
getid : function(id,callback){
var User = DAO.executeQuery("select * from ms_customer WHERE id = '" + id + "';", function(rows,id){
callback(rows[0].id);
});
},
}
控制器:
var customerModel = require('../model/customer');
module.exports = {
deleteduserv2 : function(req,res){
var id = req.headers['id'];
customerModel.getid(id, function(id,err,result,fields){
if(err){
console.log(err);
return res.status(500).json({code: "UserDeleteFailed", message: "Error while finding the data"});
}
customerModel.deleteduser(id, function(err,result,fields){
if(err)
{
console.log(err);
return res.status(500).json({code: "UserDeleteFailed", message: "Error while deleting the data"});
}
return res.status(200).json({code: "CustomerDeleted"});
});
});
},
}
请帮助..