This commit is contained in:
2026-05-04 04:02:50 +05:00
parent 0c19af34c3
commit 4ddcaec7c8
6 changed files with 119 additions and 10 deletions
+7 -3
View File
@@ -41,6 +41,7 @@ export const useCanvas = () => {
}
const parseCanvasJson = (json: any): CanvasData => {
if (!json) return { nodes: [], edges: [] }
const nodes = (json.nodes || []).map((n: any) => ({
id: n.id,
type: n.type,
@@ -88,11 +89,14 @@ export const useCanvas = () => {
return token ? { Authorization: `Bearer ${token}` } : {}
}
const loadCanvas = async (id: string): Promise<CanvasData> => {
const data = await $fetch(`/api/canvas/${id}`, {
const loadCanvas = async (id: string): Promise<{ canvas: CanvasData, role: string }> => {
const data = await $fetch<{ canvas: any, role: string }>(`/api/canvas/${id}`, {
headers: getAuthHeaders()
})
return parseCanvasJson(data)
return {
canvas: parseCanvasJson(data.canvas),
role: data.role
}
}
const updateNodeState = async (nodeId: string, state: string) => {
+6 -3
View File
@@ -8,16 +8,19 @@ export default defineEventHandler(async (event) => {
const canvas = await prisma.canvas.findUnique({ where: { id } })
if (!canvas) throw createError({ statusCode: 404, message: 'Canvas not found' })
const user = tryLazyEventHandler(event, () => requireAuth(event)) || { id: null, role: 'guest' }
let user = { id: null, role: 'guest' } as any
try {
user = requireAuth(event)
} catch (e) {}
// Определение роли
let userRole = 'viewer'
if (user.id === canvas.ownerId) userRole = 'owner'
else if (user.role === 'admin') userRole = 'admin'
else if (canvas.groupId) {
const membership = await prisma.groupMember.findUnique({
const membership = user.id ? await prisma.groupMember.findUnique({
where: { userId_groupId: { userId: user.id as string, groupId: canvas.groupId } }
})
}) : null
if (membership) userRole = membership.role
else if (!canvas.isPublic) throw createError({ statusCode: 403, message: 'Access denied' })
} else if (!canvas.isPublic) {
+6 -4
View File
@@ -29,10 +29,12 @@ export default defineEventHandler(async (event) => {
let completedTasks = 0
for (const canvas of canvases) {
const nodes = (canvas.nodes as any[]) || []
const tasks = nodes.filter(n => n.type === 'task')
totalTasks += tasks.length
completedTasks += tasks.filter(t => t.data?.state === 'completed' || t.state === 'completed').length
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, так как модели нет в схеме)