我如何得到验证回调未定义的节点,表达

时间:2018-06-17 14:57:48

标签: mysql node.js express

我的代码有问题..

如果我使用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"});   
        });
      });
    },

}

请帮助..

0 个答案:

没有答案