I'm using express,and pgp for backend development and so i have to update user data.
I'm receiving user object in req.body
and user id as req.params.id
. I've printed them out in console an they're right. So then i'm moving forward to
res.status(200).json({
user: await usersDB.updateUserById(req.body, req.params.id)
});
And here nothing happens
here are all code samples
userRouter.js
const express = require("express");
const router = express.Router();
const usersDB = require("../modules/userDB");
const passport = require("passport");
router.put('/update/:id', passport.authenticate('jwt', {session : false}), async(req, res, next) => {
try {
console.log(req.body, req.params.id)
console.log("--------------------------------")
res.status(200).json({
user: await usersDB.updateUserById(req.body, req.params.id)
});
} catch (err) {
console.log("UsersRouter error: " + err);
res.status(500).json({Error: err});
}
});
usersDB.js
const DB = require("../config/connection");
function updateUserById(user, id) {
if (user.password == null) {
console.log("upd", user, id)
return DB.any(
"UPDATE users SET name = ($1), email = ($2) WHERE id = ($3)",
[user.name, user.email, id]
);
}
return DB.any(
"UPDATE users SET name = ($1), email = ($2), password = ($3) WHERE id = ($4)",
[user.name, user.email, user.password, id]
);
}
I cant still figure out why I'm not stepping in.
Comments
Post a Comment