在Mongoose中有一些奇怪的错误

时间:2017-06-27 06:10:48

标签: javascript node.js mongoose

我正在使用node和mongoose的计费系统。但是我收到了一个意想不到的错误!

我已经检查过这些错误事件,但我可能会遗漏一些东西。

代码

func.makeTxn  = function(inuser, info, save, callback ){
  var txnType = "";
  if (info.ammount < 0 ) {
    txnType = "DEBIT";
  } else {
    txnType = "CREDIT";
  }
  var txnID;
  var d = new Date();
  txnID = d.getUTCDate().toString();
  txnID += d.getUTCMonth().toString();
  txnID += d.getUTCFullYear().toString();
  txnID += d.getUTCHours().toString();
  txnID += d.getUTCHours().toString();
  txnID += d.getUTCMinutes().toString();
  txnID += d.getUTCMinutes().toString();
  txnID += d.getUTCSeconds().toString();
  txnID += d.getUTCMilliseconds().toString();
  statementDB.create({
    user: inuser,
    txnId: txnID,
    txnType: txnType,
    ammount: info.ammount,
    reason: info.reason,
    status: info.status,
  }, function(err, txn){
    if (err) {
      callback(false); // Run Callback With Error
    } else {
      if (save) {
        userDB.findById(inuser, function(err1, userData){
          if (err1) {
            callback(false);
          } else {
            userData.credits += info.ammount;
            userData.save(function(err2){
              if (err2) {
                callback(false);
              } else {                          // func.js:115
                callback(txnID);
              }
            })
          }
        })
      } else {
        callback(txnID);
      }
    }
  })
}

错误:

events.js:182
      throw er; // Unhandled 'error' event
      ^

ReferenceError: txnId is not defined
    at G:\WorkStation\WebHosting\routs\clientarea.js:34:26
    at G:\WorkStation\WebHosting\includs\func.js:115:17
    at G:\WorkStation\WebHosting\node_modules\mongoose\lib\model.js:3748:16
    at G:\WorkStation\WebHosting\node_modules\mongoose\lib\services\model\applyHooks.js:150:20
    at _combinedTickCallback (internal/process/next_tick.js:95:7)
    at process._tickCallback (internal/process/next_tick.js:161:9)

0 个答案:

没有答案