20 lines
789 B
TypeScript
20 lines
789 B
TypeScript
import { z } from 'zod'
|
|
import { requireStageTwoSafeText, requireStageTwoUser, stageTwoApiError, stageTwoRpc, stageTwoUuid } from '~/server/utils/stage-two-supabase'
|
|
|
|
const BodySchema = z.object({ worldId: z.string().uuid(), title: z.string().trim().min(3).max(100) }).strict()
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
try {
|
|
const user = await requireStageTwoUser(event)
|
|
const body = BodySchema.parse(await readBody(event))
|
|
requireStageTwoSafeText(body.title)
|
|
const campaignId = await stageTwoRpc<string>('stage_two_create_campaign', {
|
|
p_world_id: stageTwoUuid(body.worldId, 'world id'), p_owner_id: user.id, p_title: body.title,
|
|
})
|
|
setResponseStatus(event, 201)
|
|
return { campaignId }
|
|
} catch (error) {
|
|
stageTwoApiError(error)
|
|
}
|
|
})
|