-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to insensitive case operators (#11737)
* feat: refactor apply-query & implements icontains * feat: implements icontains in app * New translations en-US.yaml * tests: fix returns the filter operators for binary * implement rest insensitive operators * fix: proposal to fix #5996 (convert "in" into "exists") * delete unused imports * fix: prevent error when operator filter value is null * fix: apply-query imports * some tests * fix: _nstarts_with not applied correctly * tests: add some filter mathematical tests
- Loading branch information
1 parent
79ddd35
commit 7e1b946
Showing
42 changed files
with
914 additions
and
154 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
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,12 @@ | ||
import { registerOperator } from './operator-register'; | ||
|
||
export default registerOperator({ | ||
operator: '_between', | ||
apply: ({ query, selectionRaw, compareValue }) => { | ||
let value = compareValue; | ||
if (typeof value === 'string') value = value.split(','); | ||
if (!(value instanceof Array)) throw new Error('Invalid value for between operator'); | ||
if (value.length !== 2) throw new Error('Expected two values for between operator'); | ||
query.whereBetween(selectionRaw, value as [any, any]); | ||
}, | ||
}); |
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,8 @@ | ||
import { registerOperator } from './operator-register'; | ||
|
||
export default registerOperator({ | ||
operator: '_contains', | ||
apply: ({ query, selectionRaw, compareValue }) => { | ||
query.where(selectionRaw, 'like', `%${compareValue}%`); | ||
}, | ||
}); |
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,8 @@ | ||
import { registerOperator } from './operator-register'; | ||
|
||
export default registerOperator({ | ||
operator: '_ends_with', | ||
apply: ({ query, selectionRaw, compareValue }) => { | ||
query.where(selectionRaw, 'like', `%${compareValue}`); | ||
}, | ||
}); |
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,8 @@ | ||
import { registerOperator } from './operator-register'; | ||
|
||
export default registerOperator({ | ||
operator: '_eq', | ||
apply: ({ query, selectionRaw, compareValue }) => { | ||
query.where(selectionRaw, '=', compareValue); | ||
}, | ||
}); |
8 changes: 8 additions & 0 deletions
8
api/src/utils/apply-query/operators/greather-than-equals.operator.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,8 @@ | ||
import { registerOperator } from './operator-register'; | ||
|
||
export default registerOperator({ | ||
operator: '_gte', | ||
apply: ({ query, selectionRaw, compareValue }) => { | ||
query.where(selectionRaw, '>=', compareValue); | ||
}, | ||
}); |
8 changes: 8 additions & 0 deletions
8
api/src/utils/apply-query/operators/greather-than.operator.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,8 @@ | ||
import { registerOperator } from './operator-register'; | ||
|
||
export default registerOperator({ | ||
operator: '_gt', | ||
apply: ({ query, selectionRaw, compareValue }) => { | ||
query.where(selectionRaw, '>', compareValue); | ||
}, | ||
}); |
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,11 @@ | ||
import { registerOperator } from './operator-register'; | ||
|
||
export default registerOperator({ | ||
operator: '_in', | ||
apply: ({ query, selectionRaw, compareValue }) => { | ||
let value = compareValue; | ||
if (typeof value === 'string') value = value.split(','); | ||
if (!(value instanceof Array)) throw new Error('Invalid value for in operator'); | ||
query.whereIn(selectionRaw, value as string[]); | ||
}, | ||
}); |
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,70 @@ | ||
import betweenOperator from './between.operator'; | ||
import containsOperator from './contains.operator'; | ||
import endsWithOperator from './ends-with.operator'; | ||
import equalsOperator from './equals.operator'; | ||
import greatherThanEqualsOperator from './greather-than-equals.operator'; | ||
import greatherThanOperator from './greather-than.operator'; | ||
import inOperator from './in.operator'; | ||
import insensitiveContainsOperator from './insensitive-contains.operator'; | ||
import insensitiveEndsWithOperator from './insensitive-ends-with.operator'; | ||
import insensitiveEqualsOperator from './insensitive-equals.operator'; | ||
import insensitiveNotContainsOperator from './insensitive-not-contains.operator'; | ||
import insensitiveNotEndsWithOperator from './insensitive-not-ends-with.operator'; | ||
import insensitiveNotEqualsOperator from './insensitive-not-equals.operator'; | ||
import insensitiveNotStartsWithOperator from './insensitive-not-starts-with.operator'; | ||
import insensitiveStartsWithOperator from './insensitive-starts-with.operator'; | ||
import intersectsBboxOperator from './intersects-bbox.operator'; | ||
import intersectsOperator from './intersects.operator'; | ||
import isEmptyOperator from './is-empty.operator'; | ||
import isNotEmptyOperator from './is-not-empty.operator'; | ||
import isNotNullOperator from './is-not-null.operator'; | ||
import isNullOperator from './is-null.operator'; | ||
import lessThanEqualsOperator from './less-than-equals.operator'; | ||
import lessThanOperator from './less-than.operator'; | ||
import notBetweenOperator from './not-between.operator'; | ||
import notContainsOperator from './not-contains.operator'; | ||
import notEndsWithOperator from './not-ends-with.operator'; | ||
import notEqualsOperator from './not-equals.operator'; | ||
import notInOperator from './not-in.operator'; | ||
import notIntersectsBboxOperator from './not-intersects-bbox.operator'; | ||
import notIntersectsOperator from './not-intersects.operator'; | ||
import notStartsWithOperator from './not-starts-with.operator'; | ||
import { OperatorRegister } from './operator-register'; | ||
import startsWithOperator from './starts-with.operator'; | ||
|
||
const operators = [ | ||
isNullOperator, | ||
isNotNullOperator, | ||
isEmptyOperator, | ||
isNotEmptyOperator, | ||
equalsOperator, | ||
notEqualsOperator, | ||
containsOperator, | ||
notContainsOperator, | ||
startsWithOperator, | ||
notStartsWithOperator, | ||
endsWithOperator, | ||
notEndsWithOperator, | ||
greatherThanOperator, | ||
greatherThanEqualsOperator, | ||
lessThanOperator, | ||
lessThanEqualsOperator, | ||
inOperator, | ||
notInOperator, | ||
betweenOperator, | ||
notBetweenOperator, | ||
intersectsOperator, | ||
notIntersectsOperator, | ||
intersectsBboxOperator, | ||
notIntersectsBboxOperator, | ||
insensitiveContainsOperator, | ||
insensitiveNotContainsOperator, | ||
insensitiveEqualsOperator, | ||
insensitiveNotEqualsOperator, | ||
insensitiveStartsWithOperator, | ||
insensitiveNotStartsWithOperator, | ||
insensitiveEndsWithOperator, | ||
insensitiveNotEndsWithOperator, | ||
]; | ||
|
||
export default operators.reduce((a, b) => ({ ...a, [b.operator]: b }), {}) as Record<string, OperatorRegister>; |
Oops, something went wrong.