无法读取未定义的属性'uuid'?

时间:2019-01-23 05:42:32

标签: node.js sequelize.js

当我尝试将主体对象插入钱包表时,我无法找到所有钱包表..当我尝试管理日志时,它通过错误消息msg无法读取未定义的属性'uuid'

  

无法读取未定义钱包2022的属性'uuid'       {cid:2022,存款:“ 56”,状态:“成功”}       正在执行(默认):INSERT INTO walletidciddeposit)值(DEFAULT,2022,'56');       剩余的:undefined       未捕获的错误{文件名:'\ cl-api-master \ services \ WalletService.js',        行:78,        行:37,        消息:“无法读取未定义的属性\'0 \',        类型:“ TypeError”,

  transaction model
      'use strict';
       module.exports = (sequelize, DataTypes) => {
        var Model = sequelize.define('transaction', {
        id: { type: DataTypes.INTEGER, field: 'id', primaryKey: true, utoIncrement: true},
        name: { type: DataTypes.STRING, field: 'name'},
        cardnum: { type: DataTypes.STRING, field: 'cardnum'},
        amount: {type: DataTypes.INTEGER,field:'amount'},
        amountsplit: {type: DataTypes.INTEGER,field:'amountsplit'},
        netamtdebt: {type: DataTypes.INTEGER,field:'netamtdebt'},
        addedon: {type:DataTypes.DATE, field:'addedon'},
        payumoneyid: {type: DataTypes.INTEGER,field:'payumoneyid'},
        txnid: {type: DataTypes.INTEGER, field: 'txnid'},   
        txnstatus:{type:DataTypes.STRING, field:'txnstatus'},
        txnmsg:{type:DataTypes.STRING, field:'txnmsg'},    
        email: {type:DataTypes.STRING, field:'email'},
        mobile: {type:DataTypes.INTEGER, field:'mobile'},
        bankrefnum: {type:DataTypes.STRING, field:'bankrefnum'},
        custcardnum:  {type:DataTypes.STRING, field:'custcardnum'},
        pgtype:  {type:DataTypes.STRING, field:'pgtype'},
        productinfo:  {type:DataTypes.STRING, field:'productinfo'},
        status: {type:DataTypes.STRING, field:'status'}
         }, {
        tableName: 'transaction',
        timestamps: false
      }); 
transaction controller:
    const transaction = require('../models').transaction;
    const wallet = require('../models').wallet;
    const User = require('../models').User;
    const Card = require('../models').card;
    const recharge = require('../models').recharge;
    var AuthService = require('../services/AuthService');
    var WalletService = require('../services/WalletService');

    const create =  async function(req, res){

    res.setHeader('Content-Type', 'application/json');
    let  err, trans, user, card , wallet;
     let transaction_info = req.body;  
    //   let recharg = recharge;   
     [err, trans] = await to(transaction.create(transaction_info));

    //  [err, card] = await to(Card.findOne({ where : {cardNum : t  
      ransaction_info.cardnum}}));
    //   console.log('request =',res);[err, user] = await to(User.findOne (        {where:{cardNum: transaction_info.cardnum}}));
        // console.log('request =',res);
    if(err){
         return ReE(res, err);
        }   
        if ('amount' in transaction_info){
            var amount = {
                cid : user.id,
                deposit : transaction_info.amount,
                status : transaction_info.status
            } 
            wallet = await WalletService.updatefrompayu(amount);
            console.log('wallet_info : <<<<<< ' + JSON.stringify(wallet));
            trans.cardnum = User.id;
            console.log('order <<<<<<' + JSON.stringify(trans));
        }
        [err, trans] = await to (transaction.save());
        if(err) return ReE(res, err, 422);
     let transaction_json = trans.toWeb();
     return ReS(res,{trans:transaction_json}, 201);
      }

     module.exports.create = create;
  walletservice.js:

       const Wallet = require('../models').wallet;
       const validator     = require('validator')
     const updatefrompayu = async function(body){
      let err, wallet, remaining;
      let wallet_inf = body; 
      var updated  = false;
    console.log('body'+ JSON.stringify(body));  

     Wallet.findAll(
        {
            limit :1,      
            where : {
                cid : wallet_inf.cid
            },
            transaction: [
                ['id', 'DESC']
            ]
        }
     ).then((result) => {
        console.log("direct query : " +result);
     }).catch((err) => {
        console.log("direct query error: " +err + " wallet " + wallet_inf.cid);
     });
     [err, remaining] = await to(Wallet.findAll(
        {
            limit :1,      
            where : {
                cid : wallet_inf.cid
            },
            transaction: [
                ['id', 'DESC']
            ]
        }
    ));
    // console.log("remaining :" + remaining);
    if(wallet_inf.status == 'success'){
    console.log(wallet_inf);
    [err, wallet] = await to(Wallet.create(wallet_inf));    
    if(err) return TE(JSON.stringify(err));   
    console.log("remaining :" + remaining);
        wallet.available = remaining[0].available + wallet_inf.deposit;
        wallet.comments = new Date();   
        updated = true;
        [err, wallet] = await to(instance.save());
        if(err) return TE(JSON.stringify(err));
    }
    else {
        wallet.available = wallet_inf.deposit;
        wallet.comments = new Date();
        TE('Please check your balance')
    }
    console.log("avalible balance:" + wallet.available);  
    return wallet;
     }
     module.exports.updatefrompayu = updatefrompayu;

在这里,我试图将交易表金额明细插入钱包。

0 个答案:

没有答案