mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2025-12-11 08:46:16 +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(
|
||||
filter: SCSearchValueFilter,
|
||||
): QueryDslSpecificQueryContainer<'term'> | QueryDslSpecificQueryContainer<'terms'> {
|
||||
return Array.isArray(filter.arguments.value)
|
||||
? {
|
||||
terms: {
|
||||
[`${filter.arguments.field}.raw`]: filter.arguments.value,
|
||||
):
|
||||
| QueryDslSpecificQueryContainer<'exists'>
|
||||
| QueryDslSpecificQueryContainer<'term'>
|
||||
| QueryDslSpecificQueryContainer<'terms'> {
|
||||
switch (typeof filter.arguments.value) {
|
||||
case 'undefined': {
|
||||
return {
|
||||
exists: {
|
||||
field: filter.arguments.field,
|
||||
},
|
||||
}
|
||||
: {
|
||||
};
|
||||
}
|
||||
case 'string': {
|
||||
return {
|
||||
term: {
|
||||
[`${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.
|
||||
*
|
||||
* Leaving the value out will check if the field exists.
|
||||
*/
|
||||
value: string | string[];
|
||||
value?: string | string[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user