managing rsvps
This commit is contained in:
@@ -3,14 +3,14 @@ import { mutations } from '@/lib/mutations'
|
||||
|
||||
export async function POST(req: NextRequest, { params }: { params: { eventId: string } }) {
|
||||
const eventId = params.eventId
|
||||
const { guestBookEntryId } = await req.json()
|
||||
const { guestId } = await req.json() // ← match client
|
||||
|
||||
if (!eventId || !guestBookEntryId) {
|
||||
return NextResponse.json({ message: 'Missing eventId or guestBookEntryId' }, { status: 400 })
|
||||
if (!eventId || !guestId) {
|
||||
return NextResponse.json({ message: 'Missing eventId or guestId' }, { status: 400 })
|
||||
}
|
||||
|
||||
try {
|
||||
const added = await mutations.addEventGuest({ eventId, guestBookEntryId })
|
||||
const added = await mutations.addEventGuest({ eventId, guestBookEntryId: guestId }) // ← match expected arg
|
||||
return NextResponse.json(added)
|
||||
} catch (error) {
|
||||
console.error('Add Event Guest Error:', error)
|
||||
|
||||
24
app/api/events/create/route.ts
Normal file
24
app/api/events/create/route.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { getServerSession } from 'next-auth'
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { authOptions } from '@/app/api/auth/[...nextauth]/route'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const session = await getServerSession(authOptions)
|
||||
if (!session?.user?.id) {
|
||||
return new NextResponse('Unauthorized', { status: 403 })
|
||||
}
|
||||
|
||||
const { name, date, location } = await req.json()
|
||||
|
||||
const event = await prisma.event.create({
|
||||
data: {
|
||||
name,
|
||||
date: date ? new Date(date) : undefined,
|
||||
location,
|
||||
creatorId: session.user.id,
|
||||
},
|
||||
})
|
||||
|
||||
return NextResponse.json(event)
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import { getServerSession } from 'next-auth'
|
||||
import { authOptions } from '@/app/api/auth/[...nextauth]/route'
|
||||
import { mutations } from '@/lib/mutations';
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const session = await getServerSession(authOptions)
|
||||
if (!session?.user) return new NextResponse('Unauthorized', { status: 401 });
|
||||
|
||||
const body = await req.json();
|
||||
const { name, date, location } = body;
|
||||
|
||||
const event = await mutations.createEvent({
|
||||
name,
|
||||
date,
|
||||
location,
|
||||
creatorId: session.user.id,
|
||||
});
|
||||
|
||||
return NextResponse.json(event)
|
||||
}
|
||||
Reference in New Issue
Block a user