Using the Sequelize ORM in Express.js to query a mySQL DB.
In Express.js I have an endpoint which takes two parameters 'level' and 'topic', like this,
//Get Topic
router.get("/tasks/:level&:topic", (req, res) => {
Task.findAll({
where: {
Topic: req.params.topic,
Level: req.params.level
}
})
.then(tasks => {
res.json(tasks)
})
.catch(err => {
res.send("error: " + err)
})
})
This works fine for when I want to query for 'level AND topic'.
But sometime 'level' might be empty and I only want to query 'topic' and at other times 'topic' might be empty and I only want to query 'level'.
I would like to have many parameters in this endpoint not just the two here and be able to query any combination of those parameters.
I imagine if this is not possible that I would have to create an endpoint for every combination of parameters. Is there an easier way to do this?