title: How to make if condition in Nodejs Sequelize model query
body: <p>I'm trying to use if condition in Nodejs Sequelize query using models. </p>
  
  <p>I want to select users by <code>filter parameter</code> if there is filter parameter. If there isn't I want to select all users.
  I did that in the following way, but I hardcoded this:</p>
  
  <p><code>var filterData = {  id: { $ne: null} };</code></p>
  
  <p>Is there a proper way to do that using Sequelize? Thanks.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function getData(id, filter='') {
    var filterData = {  id: { $ne: null} };
    if (filter !== '') {
      filterData = {
        $or: [
          {firstName: {$like: '%' + filter + '%'}},
          {lastName: {$like: '%' + filter + '%'}}
        ]
      };
    }
    return models['Profile'].findAll({
      where: { profileId: id },
      include: [{
        model: models.Profile.scope('essentials'),
        where: filterData,
        as: 'entity'
      }]
    })
  }</code></pre>
  </div>
  </div>
  </p>