swell-js icon indicating copy to clipboard operation
swell-js copied to clipboard

Is it possible to make a 'OR' request with $filter?

Open tiavina-mika opened this issue 3 years ago • 0 comments

I have products like this:

[
  {
    name: 'Product 1',
    attributes: {
      width: '15',
      height: '20',
      channels: ['web', 'mobile']
    }
  },
    {
    name: 'Product 2',
    attributes: {
      width: '25',
      height: '30',
    },
  },
  {
    name: 'Product 3',
    attributes: {
      width: '10',
      height: '10',
      channels: ['web']
    }
  },
]

I want to filter products without the channels field OR a specified channels. In server side I can achieve this with swell-node like this:

await swell.get('/products', {
  limit: 50,
  where: {
    active: true,
    $or: [
      { 'attributes.channels': { $exists: false } }, // if no channels defined, take the product for everyone
      { 'attributes.channels': { $in: ['web'] } }, // for specified channels
    ],
  },
});

Is it possible to make this OR request with swell-js?

tiavina-mika avatar Jan 14 '22 13:01 tiavina-mika