fix(utils): build query withDeleted remove auto detection (#12788)

**What**
Currently, filtering data providing a `deleted_at` value will automatically apply the `withDeleted` flag which in turns remove the default constraint apply to all queries `deleted_at: null`. The problem is that it does not account for the value assign to `deleted_at` leading to inconsistent behaviour depending on the value. e.g filtering with `deleted_at: { $eq: null }` where the expectation is to only filter the non deleted record will end up returning deleted record as well by applying the `withDeleted` filters.

This pr revert this auto detection if favor of the user providing `withDeleted` explicitly, as it is already supported , plus the filters.

Further more, some integration tests demonstrate how to filter deleted records (e.g product) from the api. While the api did not properly support it, this pr adds support to pass with_deleted flags to the query and being handled accordingly to our api support. Validators have been updated and product list end point benefit from it. Also, the list config type was already accepting such value which I have translated to the remote query config.

Also, since the previous pr was adjusting the product types, I ve adjusted them to match the expectation
This commit is contained in:
Adrien de Peretti
2025-06-25 09:51:37 +02:00
committed by GitHub
parent 9d61bb7e71
commit a833c3c98c
12 changed files with 67 additions and 46 deletions

View File

@@ -449,7 +449,7 @@ medusaIntegrationTestRunner({
// BREAKING: Comparison operators changed, so eg. `gt` became `$gt`
const response = await api
.get(
`/admin/products?deleted_at[$gt]=01-26-1990&q=test`,
`/admin/products?deleted_at[$gt]=01-26-1990&with_deleted=true&q=test`,
adminHeaders
)
.catch((err) => {
@@ -519,7 +519,10 @@ medusaIntegrationTestRunner({
it("returns a list of deleted products", async () => {
const response = await api
.get(`/admin/products?deleted_at[$gt]=01-26-1990`, adminHeaders)
.get(
`/admin/products?deleted_at[$gt]=01-26-1990&with_deleted=true`,
adminHeaders
)
.catch((err) => {
console.log(err)
})