Skip to content

Instantly share code, notes, and snippets.

@noam-honig
Created October 11, 2024 07:11
Show Gist options
  • Save noam-honig/78b023c2081196dbaa74aaa4fcb236d8 to your computer and use it in GitHub Desktop.
Save noam-honig/78b023c2081196dbaa74aaa4fcb236d8 to your computer and use it in GitHub Desktop.
A way to test if an EntityFilter contains a field #remult
/**
* Checks if a filter contains a specific field
* @example
backendPreprocessFilter: async (filter) => {
// If not specific filter for deletedBy was specified - only show non deleted rows
if (!filterContains(filter, 'deletedBy')) {
return {
...filter,
deletedBy: null,
}
}
return filter
},
*/
export function filterContains<T>(filter: EntityFilter<T>, field: keyof T) {
for (let key in filter) {
if (key == field) return true
if (key === '$and') {
for (let f of filter[key]!) {
if (filterContains(f, field)) return true
}
}
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment