feat: stabilize admin dashboard, refactor group management, implement PWA, and fix routing
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import { requireAuth } from '~/server/utils/auth'
|
||||
import { prisma } from '~/server/utils/prisma'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const user = requireAuth(event)
|
||||
|
||||
// 1. Получаем группы пользователя
|
||||
const userGroups = await prisma.groupMember.findMany({
|
||||
where: { userId: user.id },
|
||||
select: { groupId: true }
|
||||
})
|
||||
const groupIds = userGroups.map(g => g.groupId)
|
||||
|
||||
// 2. Получаем все доступные канвасы
|
||||
const canvases = await prisma.canvas.findMany({
|
||||
where: {
|
||||
OR: [
|
||||
{ ownerId: user.id },
|
||||
{ groupId: { in: groupIds } },
|
||||
{ isPublic: true }
|
||||
]
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
nodes: true
|
||||
}
|
||||
})
|
||||
|
||||
// 3. Собираем задачи из всех канвасов
|
||||
const allTasks: any[] = []
|
||||
|
||||
for (const canvas of canvases) {
|
||||
const nodes = (canvas.nodes as any[]) || []
|
||||
const taskNodes = nodes.filter(node => node.type === 'task')
|
||||
|
||||
taskNodes.forEach(task => {
|
||||
allTasks.push({
|
||||
...task,
|
||||
canvasId: canvas.id,
|
||||
canvasName: canvas.name
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// Сортируем: сначала высокий приоритет, потом дата
|
||||
allTasks.sort((a, b) => {
|
||||
const pPriority = { high: 3, medium: 2, low: 1 }
|
||||
const prioA = pPriority[a.priority || a.data?.priority] || 0
|
||||
const prioB = pPriority[b.priority || b.data?.priority] || 0
|
||||
return prioB - prioA
|
||||
})
|
||||
|
||||
return { tasks: allTasks }
|
||||
})
|
||||
Reference in New Issue
Block a user