1
0
Fork 0
mirror of synced 2024-09-20 03:08:18 +12:00

Don't trim prefixed keys

This commit is contained in:
Adria Navarro 2024-08-12 10:56:06 +02:00
parent b1d78f129b
commit ee5c4e8ed8
2 changed files with 60 additions and 1 deletions

View file

@ -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]
}

View file

@ -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 } }],
},
})
})
})
})