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.
CodePudding user response:
return res.json({ error: false, data: results, message: 'User Updated Successfully' });
should work.
CodePudding user response:
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.