feat: prisma schema, groups API, deploy workflow
This commit is contained in:
@@ -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