Don't trim prefixed keys
This commit is contained in:
parent
b1d78f129b
commit
ee5c4e8ed8
|
@ -1,3 +1,4 @@
|
|||
import { db } from "@budibase/backend-core"
|
||||
import { isLogicalSearchOperator, SearchFilters } from "@budibase/types"
|
||||
import { cloneDeep } from "lodash/fp"
|
||||
|
||||
|
@ -31,7 +32,12 @@ export const removeInvalidFilters = (
|
|||
const filter = result[filterKey]
|
||||
for (const columnKey of Object.keys(filter)) {
|
||||
if (
|
||||
!validFields.map(f => f.toLowerCase()).includes(columnKey.toLowerCase())
|
||||
!validFields
|
||||
.map(f => f.toLowerCase())
|
||||
.includes(columnKey.toLowerCase()) &&
|
||||
!validFields
|
||||
.map(f => f.toLowerCase())
|
||||
.includes(db.removeKeyNumbering(columnKey).toLowerCase())
|
||||
) {
|
||||
delete filter[columnKey]
|
||||
}
|
||||
|
|
|
@ -92,5 +92,58 @@ describe("query utils", () => {
|
|||
}
|
||||
expect(result).toEqual(expected)
|
||||
})
|
||||
|
||||
it("keeps filter key numering", () => {
|
||||
const prefixedFilters: SearchFilters = {
|
||||
equal: { "1:one": "foo" },
|
||||
$or: {
|
||||
conditions: [
|
||||
{
|
||||
equal: { "2:one": "foo2", "3:two": "bar" },
|
||||
notEmpty: { "4:one": null },
|
||||
$and: {
|
||||
conditions: [
|
||||
{
|
||||
equal: { "5:three": "baz", two: "bar2" },
|
||||
notEmpty: { forth: null },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
$and: {
|
||||
conditions: [{ equal: { "6:one": "foo2" }, notEmpty: { one: null } }],
|
||||
},
|
||||
}
|
||||
|
||||
const result = removeInvalidFilters(prefixedFilters, [
|
||||
"one",
|
||||
"three",
|
||||
"forth",
|
||||
])
|
||||
expect(result).toEqual({
|
||||
equal: { "1:one": "foo" },
|
||||
$or: {
|
||||
conditions: [
|
||||
{
|
||||
equal: { "2:one": "foo2" },
|
||||
notEmpty: { "4:one": null },
|
||||
$and: {
|
||||
conditions: [
|
||||
{
|
||||
equal: { "5:three": "baz" },
|
||||
notEmpty: { forth: null },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
$and: {
|
||||
conditions: [{ equal: { "6:one": "foo2" }, notEmpty: { one: null } }],
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue