title: Optional parameters on sequelize query
body: <p>Good morning.</p>
  
  <p>I'm quite new to NodeJS / sequelize world and I'm currently facing a problem while trying to display a dashboard on screen.</p>
  
  <p>This dashboard has three filters: two dates (period), client name, and employee name. The user can select none, one, two, or all the filters and my database needs to work accordingly.</p>
  
  <p>That being said, my problem is with Sequelize because I don't know how to treat this problem of parameters not being "always" there.</p>
  
  <p>I've seen this question: </p>
  
  <p><a href="https://stackoverflow.com/questions/36466395/sequelize-optional-where-clause-parameters">Sequelize optional where clause parameters?</a></p>
  
  <p>but this answer doesn't work anymore. I also tried another way of building the where clause, but I failed on it as well (mainly due to sequelize operators).
  The last thing I tried was to make a single query with all parameters included but try to find some value (or flag) that would make sequelize ignore the parameter, for the case when the parameter was no there*, but it looks like Sequelize doesn't have anything like that.</p>
  
  <p>* I've read a question here that has an answer saying that <code>{}</code> would do the trick but I tried that as well but didn't work.</p>
  
  <p>In summary: I need to make a query that can "change" over time, for example:</p>
  
  <pre><code>Foo.findAll({
    where: { 
    id : 1,
    }
  });
  
  Foo.findAll({
    where: { 
    id {
     [Op.in] : [1,2,3,4,5]
    },
    name: "palmeiira",
    }
  });
  </code></pre>
  
  <p>Do you know a way of doing it without the need of using a lot if / switch statements?</p>
  
  <p>I'm currently using Sequelize v. 5.5.1.</p>
  
  <p><strong>Update</strong></p>
  
  <p>I tried doing as suggested by @Anatoly and created a function to build the parameters. It was something like that. (I tried a "smaller" version just to test)</p>
  
  <pre><code>async function test() {
    const where = {};
    where[Op.and] = [];
    where[Op.eq].push({
      id: {
      [Op.in]: [1,2,3] 
      }
    });
  
    return where;
  }
  </code></pre>
  
  <p>I setted the return value to a const:</p>
  
  <pre><code>const query = await test()
  </code></pre>
  
  <p>And tried <code>console.log(query)</code>
  The result was: <strong>{ [Symbol(and)]: [ { id: [Object] } ] }</strong>, which made me believe that the problem was parsing the <code>Op</code>  part so i tried using <code>'Op.and'</code> and <code>'Op.in'</code> to avoid that and it solved this problem, but led to another on sequelize that said <strong>Invalid value</strong></p>
  
  <p>Do you have any idea where is my error ?</p>
  
  <p>P.S.: @Anatoly very nice idea you gave me on original answer. Thank you very much.</p>