Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

TypeError: Cannot read property 'connectionFactory' of undefined

Não tou conseguindo resolver... Help!

src/config/express.js

const express = require('express');
const consign = require('consign');
const bodyParser = require('body-parser');

module.exports = () => {
    let app = express();
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({extended: false}));

    consign()
        .include('src/controllers')
        .then('src/database')
        .into(app);    

    return app;
}

src/database/connectionFactory.js

const mysql = require('mysql');

function createDBConnection() {
    return mysql.createConnection({
        host: "localhost",
        user: "root",
        password: "",
        database: "db_soupublicador"
    });
}

module.exports = function(){
    return createDBConnection;
}


src/database/PublisherDAO.js

function PublisherDAO(connection) {
    this._connection = connection;
}

PublisherDAO.prototype.save = (publisher, callback) => {
    this._connection.query('INSERT INTO publishers SET ?', publisher, callback);
}

PublisherDAO.prototype.listAll = (callback) => {
    this._connection.query('select * from publishers', callback);
} 

PublisherDAO.prototype.findByID = (id, callback) => {
    this._connection.query("select * from publishers where id = ?",[id], callback);
}

module.exports = () => {
    return PublisherDAO;
};

src/controllers/publisher.js

module.exports = (app) => {

    app.get("/publisher", (req, resp) => {
        let connection = app.database.connectionFactory();
        let PublisherDAO = new app.PublisherDAO(connection);

        PublisherDAO.listAll((errors, results) => {
            console.log(results);
        });
    });
}
1 resposta
solução!

Oi Andre, acho que você precisa informar o src no caminho do app.

app.src.database.connectionFactory();

Testa pra mim?