Update method does not update in the database

0

I have a problem at the time of editing, when I click on the button it looks for the information of the fields in the console.log, already has the ID in the route also the problem is that it does not update the information in the bank, p>

exports.edit = function (req, res){
    var editaRegiao = req.body;
    var municipiosarray = [];

    for(var i = 0; i < editaRegiao.municipio.length; i++){
      municipiosarray.push(editaRegiao.municipio[i].id);
    }
    municipiosarray.toString()

    console.log(req.body);
      client.query('update cnes.regiao set descricao = ' + editaRegiao.descricao + ', municipio = ' + editaRegiao.municipio + 'where codigoregiao = ' + req.params.id, (err, result) => {
        if (err) return res.json(err);
        console.log(err);
        console.log(result);
        return res.json(result.rows);
      })
};
    
asked by anonymous 22.02.2018 / 14:21

1 answer

0

I believe the problem is in the SQL assembly, because the descrição field seems to me to be a string, and the way it's mounted you do not use quotation marks (Also valid for other fields of type string .

Try this:

exports.edit = function (req, res){
    var editaRegiao = req.body;
    var municipiosarray = [];

    for(var i = 0; i < editaRegiao.municipio.length; i++){
      municipiosarray.push(editaRegiao.municipio[i].id);
    }
    municipiosarray.toString()

    console.log(req.body);
      client.query('update cnes.regiao set descricao = "' + editaRegiao.descricao + '", municipio = "' + editaRegiao.municipio + '" where codigoregiao = ' + req.params.id, (err, result) => {
        if (err) return res.json(err);
        console.log(err);
        console.log(result);
        return res.json(result.rows);
      })
};

And another, there was a gap between your municipality and your where clause.

I hope I have helped.

    
22.02.2018 / 15:15