Why doesn't it return the user from the database by id?

Viewed 33

I use ORM Sequelize(Postgres). I wrote a code that should return user data by user id, but either it just doesn't return anything, or it says "Support for {where: 'raw query'} has been removed.".

async findOne(req,res) {
    try {
        const {id} = req.body;
        console.log(id);
        const user = await User.findOne({where: id})
        return res.json({user});
    } catch (e) {
        console.log(e.message);
    }
}

router.post('/getOne', userController.findOne);
1 Answers

You should use an object notation in order to indicate the condition id=:id:

const user = await User.findOne({where: { id: id } })
// OR 
const user = await User.findOne({where: { id } })
Related