🎉 init
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { generateSlug } from '../../shared/utils/slug'
|
||||
import { useDb } from '../database/client'
|
||||
import { participants, pots } from '../database/schema'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event)
|
||||
const name = typeof body?.name === 'string' ? body.name.trim() : ''
|
||||
const currency = typeof body?.currency === 'string' ? body.currency.trim().toUpperCase() : ''
|
||||
const creatorName = typeof body?.creatorName === 'string' ? body.creatorName.trim() : ''
|
||||
|
||||
if (!name || !currency || !creatorName) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'name, currency and creatorName are required' })
|
||||
}
|
||||
|
||||
const db = useDb()
|
||||
const slug = generateSlug()
|
||||
|
||||
await db.insert(pots).values({ slug, name, currency })
|
||||
const [creator] = await db.insert(participants).values({ potSlug: slug, name: creatorName }).returning()
|
||||
|
||||
return { slug, name, currency, creator }
|
||||
})
|
||||
Reference in New Issue
Block a user