Skip to content

fix(api): combine range conditions on the same field in list queries - #180

Open
wakqasahmed wants to merge 1 commit into
zonelessdev:mainfrom
wakqasahmed:fix/issue-179-range-filter-merge
Open

wakqasahmed wants to merge 1 commit into
zonelessdev:mainfrom
wakqasahmed:fix/issue-179-range-filter-merge

Conversation

@wakqasahmed

Copy link
Copy Markdown

Description

This fixes list filters that set two bounds on the same field, like created[gte] with created[lte], so both bounds are applied instead of only the last one. Database.Query used to spread each parameter's filter into one object, which made { created: { $lte } } replace { created: { $gte } }. It now merges operator conditions that target the same field, and keeps the old replace behaviour for plain equality values.

Fixes #179

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactoring
  • Documentation

How Was This Tested?

  • Unit tests
  • Integration tests
  • Manual testing

I added apps/api/src/__tests__/Database.spec.ts, which checks the filter Query passes to the model's find. It covers a gte/lte range on created alongside an equality on another field, a gt/lt range combined with a startAfter cursor, and two equality conditions on one field, where the last one still wins. The first two failed on main and pass with this change. I also ran npx nx test api (33 suites, 506 tests passing), npm run format:check, eslint on the changed files and npx nx build api.

Screenshots (if applicable)

N/A

Checklist

  • Self-reviewed my code
  • No new warnings
  • Existing tests still pass
  • Breaking changes are documented above

Database.Query spread each parameter's filter into one object, so a second condition on the same key (e.g. created[lte] after created[gte]) replaced the first. Merge operator conditions on the same field instead, and keep replacing for plain equality values.

Fixes zonelessdev#179
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

Successfully merging this pull request may close these issues.

[BUG] Range filters on the same field drop one side (created[gte] with created[lte])

1 participant