feat: prisma schema, groups API, deploy workflow
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { requireAuth } from '~/server/utils/auth'
|
||||
import { groups, userGroups } from '~/server/utils/db'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const user = requireAuth(event)
|
||||
const body = await readBody(event)
|
||||
const { name, description = '', isPublic = true } = body
|
||||
|
||||
if (!name?.trim()) {
|
||||
throw createError({ statusCode: 400, message: 'Group name is required' })
|
||||
}
|
||||
|
||||
const id = `group-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`
|
||||
const now = new Date().toISOString()
|
||||
|
||||
const group = { id, name: name.trim(), description, isPublic, createdAt: now, updatedAt: now, ownerId: user.id }
|
||||
groups.set(id, group)
|
||||
|
||||
userGroups.set(`${user.id}-${id}`, {
|
||||
userId: user.id,
|
||||
groupId: id,
|
||||
role: 'admin',
|
||||
joinedAt: now
|
||||
})
|
||||
|
||||
return { group }
|
||||
})
|
||||
Reference in New Issue
Block a user