1
0
Fork 0
mirror of synced 2024-09-20 11:27:56 +12:00

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

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" }])
})
})
})