I'm trying to write a constraint code that will display a message when someone tries to search for an id that doesn't exist in the database (PostgreSQL) but the if statement code below doesn't seem to do anything I keep getting status 200 ok on postman even though the id doesn't seem to exist. How can I fix this?
Code below:
Database query:
const findFruit = async (req, res) => {
const {id } = req.params;
try {
const findfru = await pool.query("SELECT * FROM fruits WHERE fruit_id=$1", [id]);
if (!findfru ) {
return res.status(400).send(e)
}
res.json(findfru .rows[0])
} catch (e) {
res.status(500).send(e)
}
}
Route API:
router.get("Fruits/:id", findFruit )
einres.status(400).send(e)?