fix(symbol-arch): robuste API-Endpoints + docker-entrypoint Migration/Seed
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 14m59s

This commit is contained in:
Pepe Ziberi
2026-05-21 07:05:49 +02:00
parent e9f66b2c3d
commit 56895be16f
5 changed files with 132 additions and 42 deletions

View File

@@ -3,11 +3,12 @@ import { prisma } from '@/lib/db'
import { getSession } from '@/lib/auth'
export async function GET() {
/* ─── 1. Global library (legacy IconAsset) ─── */
let categoriesWithUrls: any[] = []
try {
const user = await getSession()
const tenantId = user?.tenantId
/* ─── 1. Global library (legacy IconAsset) ─── */
const categoryWhere: any = tenantId
? { OR: [{ tenantId: null }, { tenantId }] }
: {}
@@ -34,7 +35,7 @@ export async function GET() {
hiddenIconIds = tenant?.hiddenIconIds || []
}
const categoriesWithUrls = categories.map((cat: any) => ({
categoriesWithUrls = categories.map((cat: any) => ({
...cat,
icons: cat.icons
.filter((icon: any) => !hiddenIconIds.includes(icon.id))
@@ -43,10 +44,18 @@ export async function GET() {
url: `/api/icons/${icon.id}/image`,
})),
}))
} catch (err) {
console.error('Error fetching legacy icon categories:', err)
categoriesWithUrls = []
}
/* ─── 2. Tenant symbols (Phase 1 architecture) ─── */
let tenantSymbolGroups: any[] = []
let flatTenantSymbols: any[] = []
/* ─── 2. Tenant symbols (Phase 1 architecture) ─── */
let tenantSymbolGroups: any[] = []
let flatTenantSymbols: any[] = []
try {
const user = await getSession()
const tenantId = user?.tenantId
if (tenantId) {
const tenantSymbols = await (prisma as any).tenantSymbol.findMany({
@@ -70,7 +79,6 @@ export async function GET() {
: `/api/icons/${ts.id}/image`,
}))
// Group by category for sidebar display
const groups = new Map<string | null, any[]>()
for (const sym of flatTenantSymbols) {
const key = sym.categoryId || null
@@ -78,7 +86,6 @@ export async function GET() {
groups.get(key)!.push(sym)
}
// Fetch categories that have symbols but may not be in the symbol list (empty ones are omitted)
const catIds = Array.from(groups.keys()).filter(Boolean) as string[]
const tenantCategories = catIds.length
? await (prisma as any).tenantCategory.findMany({
@@ -100,9 +107,18 @@ export async function GET() {
})
tenantSymbolGroups.sort((a, b) => a.sortOrder - b.sortOrder)
}
} catch (err) {
console.error('Error fetching tenant symbols:', err)
tenantSymbolGroups = []
flatTenantSymbols = []
}
/* ─── 3. Legacy mySymbols (keep for old clients during transition) ─── */
let mySymbolsLegacy: any[] = []
try {
const user = await getSession()
const tenantId = user?.tenantId
/* ─── 3. Legacy mySymbols (keep for old clients during transition) ─── */
let mySymbolsLegacy: any[] = []
if (tenantId) {
const legacy = await (prisma as any).tenantSymbol.findMany({
where: { tenantId, iconId: { not: null } },
@@ -119,15 +135,15 @@ export async function GET() {
url: `/api/icons/${ts.icon.id}/image`,
}))
}
return NextResponse.json({
categories: categoriesWithUrls,
mySymbols: mySymbolsLegacy, // legacy shape for old clients
tenantSymbols: flatTenantSymbols, // new flat list
tenantSymbolGroups, // grouped by TenantCategory
})
} catch (error) {
console.error('Error fetching icons:', error)
return NextResponse.json({ error: 'Serverfehler' }, { status: 500 })
} catch (err) {
console.error('Error fetching legacy mySymbols:', err)
mySymbolsLegacy = []
}
return NextResponse.json({
categories: categoriesWithUrls,
mySymbols: mySymbolsLegacy,
tenantSymbols: flatTenantSymbols,
tenantSymbolGroups,
})
}