出现错误:无法读取节点js中未定义的属性'findOne'

时间:2020-11-12 13:32:01

标签: node.js

我已经创建了示例页面,并且当我运行页面node airbnb-library.js时遇到错误,Cannot read property 'findOne' of undefined谁能帮助我为什么会出现此错误?我在这里附上了我的代码,任何人都可以看一下我的代码并帮助我解决此问题吗?任何帮助将不胜感激...

db.js

const config = require('../config.json');
const mysql = require('mysql2/promise');
const { Sequelize } = require('sequelize');

module.exports = db = {};

initialize();

async function initialize() {
    // create db if it doesn't already exist
    const { host, port, user, password, database } = config.database;
    const connection = await mysql.createConnection({ host, port, user, password });
    await connection.query(`CREATE DATABASE IF NOT EXISTS \`${database}\`;`);

    // connect to db
    const sequelize = new Sequelize(database, user, password, { host: host, port: port, dialect: 'mysql' });

    // init models and add them to the exported db object
    db.User = require('../users/user.model')(sequelize);
    db.Airbnb = require('../users/airbnb.model')(sequelize);

    // sync all models with database
    await sequelize.sync();
}

airbnb-library.js

const  http  = require("http");
const requestapi = require('request');
const airbnb = require('airbnbapijs')

async function test() {
    const airbnbdata = await airbnb.newAccessToken({ username: 'dino@pushideas.com', password: 'Christmas2016!'})
    console.log(airbnbdata);
}
let airbnbdata = test();

main.js

const config = require('../../../config.json');
//console.log(config);
const jwt = require('jsonwebtoken');
const db = require('../../../_helpers/db');
const airbnb = require('airbnbapijs')
const requestapi = require('request');
const  http  = require("http");

 async newAccessToken({ username, password } = {}) {
        if (!username) {
            _log2.default.e("Airbnbapi: Can't apply for a token without a username.");
            return null;
        } else if (!password) {
            _log2.default.e("Airbnbapi: Can't apply for a token without a password.");
            return null;
        }

try {
console.log("started");
            await this.airbnblogin({"email":username,"password":password});    

        } catch (e) {     
            console.log(e);
  }
}

async airbnblogin(params) { 

        console.log("airbnb login");
        console.log("before account");
        let account = await db.Airbnb.findOne({ where: { airbnb_email: params.email, } })
}

0 个答案:

没有答案