Test relationships
This commit is contained in:
parent
ee5c4e8ed8
commit
59a164f4df
|
@ -31,14 +31,10 @@ export const removeInvalidFilters = (
|
||||||
|
|
||||||
const filter = result[filterKey]
|
const filter = result[filterKey]
|
||||||
for (const columnKey of Object.keys(filter)) {
|
for (const columnKey of Object.keys(filter)) {
|
||||||
if (
|
const possibleKeys = [columnKey, db.removeKeyNumbering(columnKey)].map(
|
||||||
!validFields
|
c => c.toLowerCase()
|
||||||
.map(f => f.toLowerCase())
|
)
|
||||||
.includes(columnKey.toLowerCase()) &&
|
if (!validFields.some(f => possibleKeys.includes(f.toLowerCase()))) {
|
||||||
!validFields
|
|
||||||
.map(f => f.toLowerCase())
|
|
||||||
.includes(db.removeKeyNumbering(columnKey).toLowerCase())
|
|
||||||
) {
|
|
||||||
delete filter[columnKey]
|
delete filter[columnKey]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,5 +145,38 @@ describe("query utils", () => {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("handles relationship filters", () => {
|
||||||
|
const prefixedFilters: SearchFilters = {
|
||||||
|
$or: {
|
||||||
|
conditions: [
|
||||||
|
{ equal: { "1:other.one": "foo" } },
|
||||||
|
{
|
||||||
|
equal: {
|
||||||
|
"2:other.one": "foo2",
|
||||||
|
"3:other.two": "bar",
|
||||||
|
"4:other.three": "baz",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ equal: { "another.three": "baz2" } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = removeInvalidFilters(prefixedFilters, [
|
||||||
|
"other.one",
|
||||||
|
"other.two",
|
||||||
|
"another.three",
|
||||||
|
])
|
||||||
|
expect(result).toEqual({
|
||||||
|
$or: {
|
||||||
|
conditions: [
|
||||||
|
{ equal: { "1:other.one": "foo" } },
|
||||||
|
{ equal: { "2:other.one": "foo2", "3:other.two": "bar" } },
|
||||||
|
{ equal: { "another.three": "baz2" } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue