-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(nestjs-query): implement unimplemented operators (#6010)
- Loading branch information
1 parent
b627c1e
commit 03557ae
Showing
3 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
"@refinedev/nestjs-query": patch | ||
--- | ||
|
||
fix: implement unimplemented operators | ||
|
||
The following filter operators have been implemented. | ||
|
||
- `containss` | ||
- `ncontainss` | ||
- `startswiths` | ||
- `nstartswiths` | ||
- `endswiths` | ||
- `nendswiths` | ||
- `nbetween` | ||
|
||
Resolves #6008 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
packages/nestjs-query/test/utils/generateFilters.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import { generateFilters } from "../../src/utils/index"; | ||
import { CrudFilter, LogicalFilter } from "@refinedev/core"; | ||
|
||
describe("generateFilters", () => { | ||
it("should generate filter based on the specified operator", () => { | ||
const testCases: { filters: CrudFilter[]; expected: any }[] = [ | ||
{ | ||
filters: [{ operator: "eq", field: "name", value: "John" }], | ||
expected: { name: { eq: "John" } }, | ||
}, | ||
{ | ||
filters: [{ operator: "ne", field: "name", value: "John" }], | ||
expected: { name: { neq: "John" } }, | ||
}, | ||
{ | ||
filters: [{ operator: "lt", field: "age", value: 20 }], | ||
expected: { age: { lt: 20 } }, | ||
}, | ||
{ | ||
filters: [{ operator: "gt", field: "age", value: 20 }], | ||
expected: { age: { gt: 20 } }, | ||
}, | ||
{ | ||
filters: [{ operator: "lte", field: "age", value: 20 }], | ||
expected: { age: { lte: 20 } }, | ||
}, | ||
{ | ||
filters: [{ operator: "gte", field: "age", value: 20 }], | ||
expected: { age: { gte: 20 } }, | ||
}, | ||
{ | ||
filters: [{ operator: "in", field: "name", value: "John" }], | ||
expected: { name: { in: "John" } }, | ||
}, | ||
{ | ||
filters: [{ operator: "nin", field: "name", value: "John" }], | ||
expected: { name: { notIn: "John" } }, | ||
}, | ||
{ | ||
filters: [{ operator: "contains", field: "name", value: "John" }], | ||
expected: { name: { iLike: "%John%" } }, | ||
}, | ||
{ | ||
filters: [{ operator: "ncontains", field: "name", value: "John" }], | ||
expected: { name: { notILike: "%John%" } }, | ||
}, | ||
{ | ||
filters: [{ operator: "containss", field: "name", value: "John" }], | ||
expected: { name: { like: "%John%" } }, | ||
}, | ||
{ | ||
filters: [{ operator: "ncontainss", field: "name", value: "John" }], | ||
expected: { name: { notLike: "%John%" } }, | ||
}, | ||
{ | ||
filters: [{ operator: "startswith", field: "name", value: "John" }], | ||
expected: { name: { iLike: "John%" } }, | ||
}, | ||
{ | ||
filters: [{ operator: "nstartswith", field: "name", value: "John" }], | ||
expected: { name: { notILike: "John%" } }, | ||
}, | ||
{ | ||
filters: [{ operator: "startswiths", field: "name", value: "John" }], | ||
expected: { name: { like: "John%" } }, | ||
}, | ||
{ | ||
filters: [{ operator: "nstartswiths", field: "name", value: "John" }], | ||
expected: { name: { notLike: "John%" } }, | ||
}, | ||
{ | ||
filters: [{ operator: "endswith", field: "name", value: "John" }], | ||
expected: { name: { iLike: "%John" } }, | ||
}, | ||
{ | ||
filters: [{ operator: "nendswith", field: "name", value: "John" }], | ||
expected: { name: { notILike: "%John" } }, | ||
}, | ||
{ | ||
filters: [{ operator: "endswiths", field: "name", value: "John" }], | ||
expected: { name: { like: "%John" } }, | ||
}, | ||
{ | ||
filters: [{ operator: "nendswiths", field: "name", value: "John" }], | ||
expected: { name: { notLike: "%John" } }, | ||
}, | ||
{ | ||
filters: [{ operator: "null", field: "name", value: true }], | ||
expected: { name: { is: null } }, | ||
}, | ||
{ | ||
filters: [{ operator: "nnull", field: "name", value: true }], | ||
expected: { name: { isNot: null } }, | ||
}, | ||
{ | ||
filters: [{ operator: "between", field: "age", value: [20, 30] }], | ||
expected: { age: { between: { lower: 20, upper: 30 } } }, | ||
}, | ||
{ | ||
filters: [{ operator: "nbetween", field: "age", value: [20, 30] }], | ||
expected: { age: { notBetween: { lower: 20, upper: 30 } } }, | ||
}, | ||
]; | ||
|
||
testCases.forEach(({ filters, expected }) => { | ||
const result = generateFilters(filters as LogicalFilter[]); | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
it("should generate filter with conditional operator", () => { | ||
const testCases: { filters: CrudFilter[]; expected: any }[] = [ | ||
{ | ||
filters: [ | ||
{ | ||
operator: "and", | ||
value: [ | ||
{ | ||
field: "name", | ||
operator: "eq", | ||
value: "John", | ||
}, | ||
{ | ||
field: "age", | ||
operator: "eq", | ||
value: 20, | ||
}, | ||
], | ||
}, | ||
], | ||
expected: { and: [{ name: { eq: "John" }, age: { eq: 20 } }] }, | ||
}, | ||
{ | ||
filters: [ | ||
{ | ||
operator: "or", | ||
value: [ | ||
{ | ||
field: "name", | ||
operator: "eq", | ||
value: "John", | ||
}, | ||
{ | ||
field: "age", | ||
operator: "eq", | ||
value: 20, | ||
}, | ||
], | ||
}, | ||
], | ||
expected: { or: [{ name: { eq: "John" }, age: { eq: 20 } }] }, | ||
}, | ||
]; | ||
|
||
testCases.forEach(({ filters, expected }) => { | ||
const result = generateFilters(filters as LogicalFilter[]); | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); |