I've been stuck on this for way too long without being able to find where is my error, I am making an API with node.js through express and all Restful functions work fine for me except the updating which gets stuck on postman "sending request" while the database is updated without problems, I suspect the error is somewhere in the response but I swear I've tried each combination that came to mind to get the response to no avail. Here's my code for this:
In the router
router.put('/:id', hlpJWT.authenticateToken, ctrProfile.updateInfo);
In the controller
updateInfo = async function (req, res, next) {
const input = {
name: req.body.name,
password: await srvAuth.cryptPass(req.body.password),
..., // other input fields
};
let user = await srvProfile.updateProfile(input);
if (user) res.json(user);
else {
res.status(404);
res.json({ error: "user not found" });
}
};
in the service
updateProfile = function (input) {
return new Promise((resolve, reject) => {
query(
"UPDATE users SET ? WHERE ?",
[
{
name: input.name,
... // more input fields
},
{ user_id: input.id },
],
function (error, result) {
if (error) {
return reject(error);
}
return resolve(result);
}
);
});
};
Thanks in advance to anyone willing to help
UPDATE: Ultimately I just updated to express v5 and it works fine there, so it definitely was error handling that was causing it, but I never figured out what specifically.