Nested-Suche hinzugefügt #59

This commit is contained in:
PxlLoewe
2025-07-16 00:24:54 -07:00
parent 844cfa4b56
commit 959ae37213

View File

@@ -23,9 +23,26 @@ export async function getData(
? { ? {
OR: [ OR: [
formattedId ? { id: formattedId } : undefined, formattedId ? { id: formattedId } : undefined,
...searchFields.map((field) => ({ ...searchFields.map((field) => {
[field]: { contains: searchTerm }, 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(Boolean),
...filter, ...filter,
} }