can someone help me to understand how to use the query function created to update a password in my database?
here is the query function in question
async function updatePassword(req, res) {
return db.none('UPDATE user_account SET password = $1 WHERE email = $2',
[req.body.password, req.body.email])
.then(function () {
res.status(200)
.json({
status: 'success',
message: 'Updated user'
});
})
.catch(error => {
console.log(error)
});
}
here is what I tried to do with fetch method put
resetPassword(){
fetch('http://url/example', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: this.email,
password: this.passwordReset,
}),
})
// Converting to JSON
.then(response => response.json())
// Displaying results to console
.then(json => console.log(json));
},
no error "{status: 'success', message: 'Updated user'}"
but nothing has changed in my database
'UPDATE user_account SET password = $1 WHERE email = $2' you pass the both req.params and req.body so in your case req.params.email pass the execution and success for it and i think this is the bad idea using both in one.