Nested $and's and $or's test

This commit is contained in:
Adria Navarro 2024-08-05 15:09:33 +02:00
parent 940a080e18
commit ebca381e9b
2 changed files with 48 additions and 6 deletions

View File

@ -370,12 +370,11 @@ class InternalBuilder {
}
if (filters.$and) {
iterate(filters.$and, (key: string, conditions: any[]) => {
query = query.where(x => {
for (const condition of conditions) {
x = this.addFilters(x, condition, table, opts)
}
})
const { $and } = filters
query = query.where(x => {
for (const condition of $and.conditions) {
x = this.addFilters(x, condition, table, opts)
}
})
}

View File

@ -2850,5 +2850,48 @@ describe.each([
},
}).toFindNothing()
})
it("can nest $and under $or filters", async () => {
await expectQuery({
$or: {
conditions: [
{
$and: {
conditions: [
{
range: { age: { low: 1, high: 8 } },
},
{ equal: { name: "Jan" } },
],
},
equal: { name: "Jane" },
},
],
},
}).toContainExactly([
{ age: 1, name: "Jane" },
{ age: 8, name: "Jan" },
])
})
it("can nest $or under $and filters", async () => {
await expectQuery({
$and: {
conditions: [
{
$or: {
conditions: [
{
range: { age: { low: 1, high: 8 } },
},
{ equal: { name: "Jan" } },
],
},
equal: { name: "Jane" },
},
],
},
}).toContainExactly([{ age: 1, name: "Jane" }])
})
})
})