fix(symbol-groups): API + Frontend auf category-Objekt-Format umgestellt – zeigt jetzt alle Kategorien korrekt
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled

This commit is contained in:
Pepe Ziberi
2026-05-21 15:25:12 +02:00
parent 9cba24aad8
commit 0cbea843ab
3 changed files with 23 additions and 27 deletions

View File

@@ -115,12 +115,12 @@ export async function GET() {
const groups = new Map<string | null, any[]>()
for (const sym of flatTenantSymbols) {
const key = sym.categoryId || null
const key = sym.categoryId || '__none__'
if (!groups.has(key)) groups.set(key, [])
groups.get(key)!.push(sym)
}
const catIds = Array.from(groups.keys()).filter(Boolean) as string[]
const catIds = Array.from(groups.keys()).filter(k => k !== '__none__') as string[]
let tenantCategories: any[] = []
if (catIds.length > 0) {
tenantCategories = await prisma.$queryRawUnsafe(
@@ -132,15 +132,12 @@ export async function GET() {
const catMap = new Map(tenantCategories.map((c: any) => [c.id, c]))
tenantSymbolGroups = Array.from(groups.entries()).map(([catId, symbols]) => {
const cat = catId ? catMap.get(catId) : null
const cat = catId !== '__none__' ? catMap.get(catId) : null
return {
categoryId: catId,
categoryName: cat ? cat.name || 'Kategorie' : 'Ohne Kategorie',
sortOrder: cat ? cat.sortOrder ?? 999 : 999,
category: cat ? { id: cat.id, name: cat.name } : null,
symbols,
}
})
tenantSymbolGroups.sort((a, b) => a.sortOrder - b.sortOrder)
}
} catch (err) {
console.error('Error fetching tenant symbols:', err)

View File

@@ -84,11 +84,13 @@ export async function GET(req: NextRequest) {
}
// Group by category
const groupedResult: Record<string, any[]> = {}
const groupedResult: Record<string, { catId: string | null; catName: string; symbols: any[] }> = {}
for (const sym of mapped) {
const catName = sym.categoryName
if (!groupedResult[catName]) groupedResult[catName] = []
groupedResult[catName].push(sym)
const key = sym.categoryId || '__none__'
if (!groupedResult[key]) {
groupedResult[key] = { catId: sym.categoryId, catName: sym.categoryName, symbols: [] }
}
groupedResult[key].symbols.push(sym)
}
// Get categories for ordering
@@ -97,16 +99,16 @@ export async function GET(req: NextRequest) {
tenantId
)
const ordered: Array<{ categoryId: string | null; categoryName: string; symbols: any[] }> = []
const ordered: Array<{ category: { id: string; name: string } | null; symbols: any[] }> = []
for (const cat of categories) {
if (groupedResult[cat.name]) {
ordered.push({ categoryId: cat.id, categoryName: cat.name, symbols: groupedResult[cat.name] })
delete groupedResult[cat.name]
if (groupedResult[cat.id]) {
ordered.push({ category: { id: cat.id, name: cat.name }, symbols: groupedResult[cat.id].symbols })
delete groupedResult[cat.id]
}
}
// Append any remaining uncategorized
for (const [catName, symbols] of Object.entries(groupedResult)) {
ordered.push({ categoryId: null, categoryName: catName, symbols })
for (const entry of Object.values(groupedResult)) {
ordered.push({ category: null, symbols: entry.symbols })
}
return NextResponse.json({ categories: ordered })