Currently, I am in the process of developing a search and filter feature for a database. This feature will allow users to apply filters and search for specific entries. The technologies I'm using for this project are TypeScript and Sequelize.
My goal is to generate a list of items that match both the applied filters and the search term entered by the user. Here's how I envision my code working:
const { Op } = require('sequelize');
let options = {};
if(searchParameters.name){
options += { [Op.like]: { itemName: '%' + searchParameters.name + '%'}}
}
return Item.findAll({
where: options
}
I want the code to only implement filters that have been provided by the user and ignore any null filters. However, I'm currently facing challenges in making this functionality work as intended.