import { requireAuth } from '~/server/utils/auth' import { prisma } from '~/server/utils/prisma' export default defineEventHandler(async (event) => { const user = requireAuth(event) // 1. Считаем канвасы (личные и где участник) const canvasCount = await prisma.canvas.count({ where: { OR: [ { ownerId: user.id }, { groupId: { not: null } } // Тут можно усложнить, но для начала так ] } }) // 2. Считаем задачи во всех доступных канвасах const canvases = await prisma.canvas.findMany({ where: { OR: [ { ownerId: user.id }, { groupId: { not: null } } ] }, select: { nodes: true } }) let totalTasks = 0 let completedTasks = 0 for (const canvas of canvases) { const nodes = canvas.nodes if (Array.isArray(nodes)) { const tasks = nodes.filter(n => n.type === 'task') totalTasks += tasks.length completedTasks += tasks.filter(t => (t.data?.state === 'completed' || t.state === 'completed')).length } } // 3. Ачивки (пока возвращаем 0, так как модели нет в схеме) const achievementCount = 0 return { stats: { canvases: canvasCount, tasks: { total: totalTasks, completed: completedTasks }, achievements: achievementCount } } })