Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double filters in querystring #100

Open
marcvan-dijk opened this issue Dec 13, 2021 · 3 comments
Open

Double filters in querystring #100

marcvan-dijk opened this issue Dec 13, 2021 · 3 comments

Comments

@marcvan-dijk
Copy link

Hi Sean,

First of all, thanks for your package, it saves a lot of time creating those queries. I'm facing an issue that deeper objects result in double queries. Please consider the following object:

{
    "filter": {
        "Nomination": {
            "ScheduledAt": {
                "ge": "2021-12-12T23:00:00.000Z",
                "le": "2021-12-13T22:59:59.999Z"
            },
            "NominationStatusValues": {
                "any": {
                    "NominationStatusID": 3
                }
            }
        }
    },
    "orderBy": "id",
    "count": true,
    "top": 15
}

this results in the following querystring (with some enters for readability):

$filter=
Nomination/ScheduledAt ge 2021-12-12T23:00:00.000Z and 
Nomination/ScheduledAt le 2021-12-13T22:59:59.999Z and 
Nomination/NominationStatusValues/any(nominationstatusvalues:nominationstatusvalues/NominationStatusID eq 3) and 
Nomination/ScheduledAt ge 2021-12-12T23:00:00.000Z and 
Nomination/ScheduledAt le 2021-12-13T22:59:59.999Z and 
Nomination/NominationStatusValues/any(nominationstatusvalues:nominationstatusvalues/NominationStatusID eq 3)
&$orderby=id&$count=true&$top=15

Am I doing something wrong or did I stumble upon a bug? I've tried several versions (6.7.1, 6.7.0, 6.6.0) but to no avail.

Thanks in advance

@anton-kirschhock
Copy link

Can confirm, we've got the exact same issue here:

let filter = {
    users: {
      firstName: { contains: 'admin' },
      isActive: { eq: true },
    },
    not: { users: { roles: { any: {} } } },
};

buildQuery({ filter });

results in:

"?$filter=contains(users/firstName,'admin') and users/isActive eq true and contains(users/firstName,'admin') and users/isActive eq true and not(users/roles/any())"

@alenkordic
Copy link

alenkordic commented May 10, 2023

@techniq We also encounter the same issue here. Using version 7.0.3.
Nested query object with multiple props on the same level, using odata "in" operator, create a duplicated query string. Duplication happens as many times as the number of props on the same level (3 props = 3 duplications).
Looking forward for solution. Thank you.

import buildODataQueryFn from 'odata-query';

const query = {
  filter: {
    components: {
      control_number: {
        in: ['0158'],
      },
      component1_number: {
        in: ['0179'],
      },
      component2_number: {
        in: ['0187'],
      },
    },
  },
};

const queryString = buildODataQueryFn(query)

console.log(queryString)

// ?$filter=components/control_number in ('0158') and components/component1_number in ('0179') and components/component2_number in ('0187') and components/control_number in ('0158') and components/component1_number in ('0179') and components/component2_number in ('0187') and components/control_number in ('0158') and components/component1_number in ('0179') and components/component2_number in ('0187')

@techniq
Copy link
Owner

techniq commented May 10, 2023

I'd be happy to review a PR, but to be honest, I don't have much time to dig into the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants