bitovi / querystring-parser

MIT License
8 stars 5 forks source link

Fix issues with null filters #31

Closed michael-dean-haynie closed 2 years ago

michael-dean-haynie commented 2 years ago

The @bitovi/sequelize-querystring-parser and @bitovi/objection-querystring-parser packages are returning errors and incorrect results when filtering on null values.

Below is a list of examples showing the http request and the response body:

Objection Issues

// 1. GET localhost:3000/students?filter[house][$ne]=null
{
    "data": [] // all students should be returned (because none have a null house)
}

// 2. GET localhost:3000/students?filter[house][$nin]=Gryffindor,null
{
    "data": [] // all non-Gryffindors should be returned
}

Sequelize Issues

// 3. GET localhost:3000/students?filter=equals(house,null)
{
    "errors": "SQLITE_ERROR: no such column: hogwarts.0"
}

// 4. GET localhost:3000/students?filter=any(house,null)
{
    "errors": "Cannot read properties of null (reading 'length')" // might be because of https://github.com/bitovi/querystring-parser/issues/32
}

// 5. GET localhost:3000/students?filter[house][$eq]=null
{
    "errors": "SQLITE_ERROR: no such column: hogwarts.0"
}

// 6. GET localhost:3000/students?filter[house][$ne]=null
{
    "errors": "SQLITE_ERROR: no such column: hogwarts.0"
}

// 7. GET localhost:3000/students?filter[house][$nin]=Gryffindor,null
{
    "errors": "Invalid value { undefined: [ 'Gryffindor', null ] }"
}

Steps to Reproduce

  1. Run the sequelize or objection example (as needed)
  2. Use postman or curl to execute the http requests in the examples above
  3. Receive the response body with errors or unexpected data

Acceptance Criteria

References