Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

114
Visualizações
PUT does not update Mysql thru REST api / JWT

I am trying to make an update request using Jwt (Tokens) and Node.Js with a backend in mysql. It just tells me in Postman that the record has been updated, i try to see where the update took place and i could not find a thing. Nothing updated.

My code is looking thus :

app.put('/api/v1/logistics/update_profile', async function (req, res, next) {
  try {
    if (
      !req.headers.authorization ||
      !req.headers.authorization.startsWith('Bearer ') ||
      !req.headers.authorization.split(' ')[1]
    ) {
      return res.status(422).json({ message: 'Please Provide Token!' });
    }

    const theToken = req.headers.authorization.split(' ')[1];
    const decoded = jwt.verify(theToken, 'fasta-logistics');

    var fullname = req.body.fullname;
    var email = req.body.email;
    var state = req.body.state;
    var city = req.body.city;
    var phone_num = req.body.phone_num;
    var company_type = req.body.company_type;
    var company_name = req.body.company_name;
    var company_regnum = req.body.company_regnum;
    var l_licensenumber = req.body.l_licensenumber;
    var company_address = req.body.company_address;

    dbConn.query(
      'UPDATE XXXXXx SET fullname =? , email =?, state=?, city=?, phone_num=?, company_type=?, company_name =?, company_regnum =?, l_licensenumber =?, company_address =?  where id =?',
      [
        fullname,
        email,
        state,
        city,
        phone_num,
        company_type,
        company_name,
        company_regnum,
        l_licensenumber,
        company_address,
        decoded.id,
      ],
      function (error, results, fields) {
        if (error) throw error;

        return res.send({
          error: false,
          data: results,
          message: 'User Updated Successfully',
        });
      }
    );
  } catch (err) {
    next(err);
  }
});

Why does it tell me the records has been updated and nothing happens? Please I need guidance here of some sort.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

return res.json({ error: false, data: results, message: 'User Updated Successfully' }); should work.

about 4 years ago · Juan Pablo Isaza Relatório

0

To be honest, I don't know how the "dbConn.query" works, but I guess you misspelled the arguments order or something like that. I can suggest you to use ORMs instead (at least query builders like knex), because they have declarative and more readable code, huge doc and community and issues like this doesn't exist in there.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda