feat: migrate Canvas and Groups API to Prisma ORM

This commit is contained in:
2026-04-26 14:37:12 +05:00
parent f9e35cb9e7
commit e040d8cacd
14 changed files with 183 additions and 223 deletions
+16 -20
View File
@@ -1,36 +1,32 @@
import { requireAuth } from '~/server/utils/auth'
import { canvases, userGroups } from '~/server/utils/db'
import type { CanvasData } from '~/server/utils/db'
import { prisma } from '~/server/utils/prisma'
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
)
const membership = await prisma.groupMember.findUnique({
where: { userId_groupId: { userId: user.id, 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)
const canvas = await prisma.canvas.create({
data: {
id,
name,
nodes,
edges,
isPublic,
ownerId: user.id,
groupId: groupId || null
}
})
return { canvas }
})
})