Nested-Suche hinzugefügt #59
This commit is contained in:
@@ -23,9 +23,26 @@ export async function getData(
|
||||
? {
|
||||
OR: [
|
||||
formattedId ? { id: formattedId } : undefined,
|
||||
...searchFields.map((field) => ({
|
||||
[field]: { contains: searchTerm },
|
||||
})),
|
||||
...searchFields.map((field) => {
|
||||
if (field.includes(".")) {
|
||||
const parts: string[] = field.split(".");
|
||||
|
||||
// Helper function to build nested object
|
||||
const buildNestedFilter = (parts: string[], index = 0): any => {
|
||||
if (index === parts.length - 1) {
|
||||
// Reached the last part - add the contains filter
|
||||
return { [parts[index] as string]: { contains: searchTerm } };
|
||||
}
|
||||
|
||||
// For intermediate levels, nest the next level
|
||||
return { [parts[index] as string]: buildNestedFilter(parts, index + 1) };
|
||||
};
|
||||
|
||||
return buildNestedFilter(parts);
|
||||
}
|
||||
|
||||
return { [field]: { contains: searchTerm } };
|
||||
}),
|
||||
].filter(Boolean),
|
||||
...filter,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user