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

Erro, erro, erro, erro....

Olá,

Não sei o que acontece, só sei que da erro o tempo todo, já copiei e colei o código do curso e o erro continua.

PagamentoDAO

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

PagamentoDAO.prototype.inserir = function (pagamento, callback) {
    this._connection.query("Insert into pagamentos set ?", pagamento,  callback);
};

PagamentoDAO.prototype.atualiza = function (pagamento, callback) {
    this._connection.query("update pagamentos set status = ? where id = ?", [pagamento.status, pagamento.id],
        callback);
};

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

Rota

app.put("/pagamentos/pagamento/:id", function (req, res) {
        console.log("Pelo menos entro aki");
        var pagamento = {};
        var id = req.params.id;
        pagamento.id = id;
        pagamento.status = "CONFIRMADO";

        let connection = app.infra.ConnectionFactory();
        let pagamentoDAO = new app.infra.PagamentoDAO(connection);
        console.log("Se não der certo, dará errado");
        pagamentoDAO.atualiza(pagamento, function (erros) {
            if (erros){
                console.log("Deu errado");
                res.status(500).send(erros);
                return;
            }
            console.log("Deu certo");
            res.send(pagamento);
        });
    });

Nem entra na função, e já fiz de tudo. O erro é esse.

➜  payfast curl http://localhost:3000/pagamentos/pagamento/5 -v
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET /pagamentos/pagamento/5 HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< X-Powered-By: Express
< Content-Security-Policy: default-src 'self'
< X-Content-Type-Options: nosniff
< Content-Type: text/html; charset=utf-8
< Content-Length: 161
< Date: Wed, 04 Apr 2018 18:22:41 GMT
< Connection: keep-alive
< 
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /pagamentos/pagamento/5</pre>
</body>
</html>
* Connection #0 to host localhost left intact
1 resposta
solução!

Descobri o erro, no terminal eu esqueci de colocar o -X PUT estava colocando assim curl http://localhost:3000/pagamentos/pagamento/5 -v e o correto é curl -X PUT http://localhost:3000/pagamentos/pagamento/7 -v

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software