mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2025-12-11 00:36:14 +00:00
feat: add ability to check for existence of a field
This commit is contained in:
6
.changeset/nine-bears-speak.md
Normal file
6
.changeset/nine-bears-speak.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@openstapps/backend": minor
|
||||||
|
"@openstapps/core": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Add the ability to filter by existence of a field
|
||||||
@@ -21,16 +21,31 @@ import {QueryDslSpecificQueryContainer} from '../../types/util.js';
|
|||||||
*/
|
*/
|
||||||
export function buildValueFilter(
|
export function buildValueFilter(
|
||||||
filter: SCSearchValueFilter,
|
filter: SCSearchValueFilter,
|
||||||
): QueryDslSpecificQueryContainer<'term'> | QueryDslSpecificQueryContainer<'terms'> {
|
):
|
||||||
return Array.isArray(filter.arguments.value)
|
| QueryDslSpecificQueryContainer<'exists'>
|
||||||
? {
|
| QueryDslSpecificQueryContainer<'term'>
|
||||||
terms: {
|
| QueryDslSpecificQueryContainer<'terms'> {
|
||||||
[`${filter.arguments.field}.raw`]: filter.arguments.value,
|
switch (typeof filter.arguments.value) {
|
||||||
|
case 'undefined': {
|
||||||
|
return {
|
||||||
|
exists: {
|
||||||
|
field: filter.arguments.field,
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
: {
|
}
|
||||||
|
case 'string': {
|
||||||
|
return {
|
||||||
term: {
|
term: {
|
||||||
[`${filter.arguments.field}.raw`]: filter.arguments.value,
|
[`${filter.arguments.field}.raw`]: filter.arguments.value,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
case 'object': {
|
||||||
|
return {
|
||||||
|
terms: {
|
||||||
|
[`${filter.arguments.field}.raw`]: filter.arguments.value,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ export interface SCValueFilterArguments extends SCSearchAbstractFilterArguments
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Value to filter. One or more values has to match the field exactly.
|
* Value to filter. One or more values has to match the field exactly.
|
||||||
|
*
|
||||||
|
* Leaving the value out will check if the field exists.
|
||||||
*/
|
*/
|
||||||
value: string | string[];
|
value?: string | string[];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user