bitovi / querystring-parser

MIT License
8 stars 5 forks source link

Fix issues with array filter operators #32

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 a when filtering with single-valued array-operators.

Below is a list of examples showing the http request and the response body. Most of the issues seem to be with the any(), $in, and $nin operators handling single values. They should be able to handle 1 or more values.

Objection Issues

// 1. GET localhost:3000/students?filter=any(house,'Gryffindor')
{
    "errors": "select `hogwarts`.* from `hogwarts` where `house` in 'Gryffindor' - SQLITE_ERROR: near \"?\": syntax error"
}

// 2. GET localhost:3000/students?filter[house][$in]=Gryffindor
{
    "errors": "select `hogwarts`.* from `hogwarts` where `house` in 'Gryffindor' - SQLITE_ERROR: near \"?\": syntax error"
}

// 3. GET localhost:3000/students?filter[house][$nin]=Gryffindor
{
    "errors": "select `hogwarts`.* from `hogwarts` where `house` not in 'Gryffindor' - SQLITE_ERROR: near \"?\": syntax error"
}

Sequelize Issues

// 4. GET localhost:3000/students?filter=any(house,'Gryffindor')
{
    "errors": "value.map is not a function"
}

// 5. GET localhost:3000/students?filter[house][$in]=Gryffindor
{
    "errors": "value.map is not a function"
}

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

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

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

Acceptance Criteria

References