So lets say I have a GET route for /movies (it's not actually movies but it would be easier to explain this way)
On client side I have a table that I want to filter movies depending on dropdown menus:
Genre, Year, Country, Type (By default they all are on ALL)
Those are also columns on the db for the movies table. I am using node-postgres
So my query would be like this:
const query = {
text: 'SELECT * FROM movies WHERE genre = $1 AND year = $2 AND country = $3 AND type = $4',
values: [genre, year, country, type],
};
But that doesn't work if the user don't choose anything from the dropdown (it would be ALL)
What would be the best way to do this so if the client sends ALL it just don't add that column to the query?