bitovi / querystring-parser

MIT License
8 stars 5 forks source link

Fix nested ands ors #35

Closed michael-dean-haynie closed 2 years ago

michael-dean-haynie commented 2 years ago

The IBM-style filter and() and or() operators should be nestable. This works for the @bitovi/sequelize-querystring-parser package but not for the @bitovi/objection-querystring-parser package.

Steps to Reproduce

  1. Run the objection example
  2. Use postman or curl to make a request with a querystring like this:
    
    // formatted readable version
    filter=or(
    equals(id,'1'),
    and(
        equals(id,'2'),
        greaterThan(id,'0')
    )
    )

// inline version filter=or(equals(id,‘1’),and(equals(id,‘2’),greaterThan(id,‘0’)))

3. The obj lib returns the following:
``` json
{
    "results": [
      {
        "fx": "where",
        "parameters": [
          "id",
          "=",
          1
        ]
      },
      {
        "fx": "where",
        "parameters": [
          "id",
          "=",
          2
        ]
      },
      {
        "fx": "where",
        "parameters": [
          "id",
          ">",
          0
        ]
      }
    ]
}
  1. Notice that the result is a flat array without any of the nesting logic preserved.

Acceptance Criteria

NOTE: #29 is dependent on this nesting logic working because the not() operator uses a nested sub-expression.