Created
October 11, 2024 07:11
-
-
Save noam-honig/78b023c2081196dbaa74aaa4fcb236d8 to your computer and use it in GitHub Desktop.
A way to test if an EntityFilter contains a field #remult
This file contains hidden or 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
/** | |
* 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