feat: prisma schema, groups API, deploy workflow
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { requireAuth } from '~/server/utils/auth'
|
||||
import { canvases } from '~/server/utils/db'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
requireAuth(event)
|
||||
const id = getRouterParam(event, 'id')
|
||||
|
||||
if (!canvases.has(id || '')) {
|
||||
throw createError({ statusCode: 404, message: 'Canvas not found' })
|
||||
}
|
||||
|
||||
canvases.delete(id || '')
|
||||
|
||||
return { success: true, message: 'Canvas deleted' }
|
||||
})
|
||||
@@ -0,0 +1,62 @@
|
||||
import { requireAuth } from '~/server/utils/auth'
|
||||
import { canvases, userGroups } from '~/server/utils/db'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const id = getRouterParam(event, 'id')
|
||||
|
||||
if (!id) {
|
||||
throw createError({ statusCode: 400, message: 'Canvas ID is required' })
|
||||
}
|
||||
|
||||
const canvas = canvases.get(id)
|
||||
if (!canvas) {
|
||||
throw createError({ statusCode: 404, message: 'Canvas not found' })
|
||||
}
|
||||
|
||||
// Check if canvas is public
|
||||
if (canvas.isPublic) {
|
||||
return {
|
||||
id: canvas.id,
|
||||
name: canvas.name,
|
||||
nodes: canvas.nodes,
|
||||
edges: canvas.edges,
|
||||
isPublic: true,
|
||||
ownerId: canvas.ownerId
|
||||
}
|
||||
}
|
||||
|
||||
// For private canvases, require authentication and check permissions
|
||||
const user = requireAuth(event)
|
||||
|
||||
// Check if user owns the canvas
|
||||
if (canvas.ownerId === user.id) {
|
||||
return {
|
||||
id: canvas.id,
|
||||
name: canvas.name,
|
||||
nodes: canvas.nodes,
|
||||
edges: canvas.edges,
|
||||
isPublic: false,
|
||||
ownerId: canvas.ownerId
|
||||
}
|
||||
}
|
||||
|
||||
// Check if user has access through group membership
|
||||
if (canvas.groupId) {
|
||||
const membership = Array.from(userGroups.values()).find(
|
||||
m => m.userId === user.id && m.groupId === canvas.groupId
|
||||
)
|
||||
if (membership) {
|
||||
return {
|
||||
id: canvas.id,
|
||||
name: canvas.name,
|
||||
nodes: canvas.nodes,
|
||||
edges: canvas.edges,
|
||||
isPublic: false,
|
||||
ownerId: canvas.ownerId,
|
||||
groupId: canvas.groupId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw createError({ statusCode: 403, message: 'Access denied' })
|
||||
})
|
||||
@@ -0,0 +1,24 @@
|
||||
import { requireAuth } from '~/server/utils/auth'
|
||||
import { canvases } from '~/server/utils/db'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
requireAuth(event)
|
||||
const id = getRouterParam(event, 'id')
|
||||
const body = await readBody(event)
|
||||
|
||||
const existing = canvases.get(id || '')
|
||||
if (!existing) {
|
||||
throw createError({ statusCode: 404, message: 'Canvas not found' })
|
||||
}
|
||||
|
||||
const updated = {
|
||||
...existing,
|
||||
...body,
|
||||
id: existing.id,
|
||||
updatedAt: new Date().toISOString()
|
||||
}
|
||||
|
||||
canvases.set(id || '', updated)
|
||||
|
||||
return { canvas: updated }
|
||||
})
|
||||
@@ -0,0 +1,46 @@
|
||||
import { requireAuth } from '~/server/utils/auth'
|
||||
import { canvases } from '~/server/utils/db'
|
||||
import type { CanvasData } from '~/server/utils/db'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const user = requireAuth(event)
|
||||
const id = getRouterParam(event, 'id')
|
||||
|
||||
if (!id) {
|
||||
throw createError({ statusCode: 400, message: 'Canvas ID is required' })
|
||||
}
|
||||
|
||||
const original = canvases.get(id)
|
||||
if (!original) {
|
||||
throw createError({ statusCode: 404, message: 'Canvas not found' })
|
||||
}
|
||||
|
||||
// Check permissions
|
||||
if (original.ownerId !== user.id && !original.isPublic) {
|
||||
throw createError({ statusCode: 403, message: 'Access denied' })
|
||||
}
|
||||
|
||||
const newId = `canvas-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
|
||||
const duplicate: CanvasData = {
|
||||
...original,
|
||||
id: newId,
|
||||
name: `${original.name} (Copy)`,
|
||||
ownerId: user.id,
|
||||
groupId: undefined, // Duplicates are personal
|
||||
isPublic: false,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
nodes: original.nodes.map(node => ({
|
||||
...node,
|
||||
id: `${node.id}-copy-${Date.now()}`
|
||||
})),
|
||||
edges: original.edges.map(edge => ({
|
||||
...edge,
|
||||
id: `${edge.id}-copy-${Date.now()}`
|
||||
}))
|
||||
}
|
||||
|
||||
canvases.set(newId, duplicate)
|
||||
|
||||
return { canvas: duplicate }
|
||||
})
|
||||
@@ -0,0 +1,34 @@
|
||||
import { requireAuth } from '~/server/utils/auth'
|
||||
import { canvases, userGroups } from '~/server/utils/db'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const user = requireAuth(event)
|
||||
|
||||
// Get all canvases the user can access
|
||||
const userGroupIds = Array.from(userGroups.values())
|
||||
.filter(membership => membership.userId === user.id)
|
||||
.map(membership => membership.groupId)
|
||||
|
||||
const accessibleCanvases = Array.from(canvases.values()).filter(canvas => {
|
||||
// User can see their own canvases
|
||||
if (canvas.ownerId === user.id) return true
|
||||
// User can see public canvases
|
||||
if (canvas.isPublic) return true
|
||||
// User can see group canvases they're a member of
|
||||
if (canvas.groupId && userGroupIds.includes(canvas.groupId)) return true
|
||||
return false
|
||||
})
|
||||
|
||||
const canvasList = accessibleCanvases.map(canvas => ({
|
||||
id: canvas.id,
|
||||
name: canvas.name,
|
||||
ownerId: canvas.ownerId,
|
||||
createdAt: canvas.createdAt,
|
||||
updatedAt: canvas.updatedAt,
|
||||
isPublic: canvas.isPublic,
|
||||
groupId: canvas.groupId,
|
||||
nodeCount: canvas.nodes.length
|
||||
}))
|
||||
|
||||
return { canvases: canvasList }
|
||||
})
|
||||
@@ -0,0 +1,36 @@
|
||||
import { requireAuth } from '~/server/utils/auth'
|
||||
import { canvases, userGroups } from '~/server/utils/db'
|
||||
import type { CanvasData } from '~/server/utils/db'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const user = requireAuth(event)
|
||||
const body = await readBody(event)
|
||||
const { name = 'New Canvas', nodes = [], edges = [], isPublic = false, groupId } = body
|
||||
|
||||
// Check group permissions if groupId is provided
|
||||
if (groupId) {
|
||||
const membership = Array.from(userGroups.values()).find(
|
||||
m => m.userId === user.id && m.groupId === groupId
|
||||
)
|
||||
if (!membership) {
|
||||
throw createError({ statusCode: 403, message: 'Not a member of this group' })
|
||||
}
|
||||
}
|
||||
|
||||
const id = `canvas-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
|
||||
const canvas: CanvasData = {
|
||||
id,
|
||||
name,
|
||||
nodes,
|
||||
edges,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
ownerId: user.id,
|
||||
groupId,
|
||||
isPublic
|
||||
}
|
||||
|
||||
canvases.set(id, canvas)
|
||||
|
||||
return { canvas }
|
||||
})
|
||||
Reference in New Issue
Block a user