managing rsvps

This commit is contained in:
briannelson95
2025-06-28 20:23:22 -04:00
parent dee9066c91
commit 28efa115ad
19 changed files with 568 additions and 197 deletions

View File

@@ -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)

View 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)
}

View File

@@ -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)
}

View File

@@ -0,0 +1,29 @@
// api/guestbook/search/route.ts
import { prisma } from '@/lib/prisma'
import { NextRequest, NextResponse } from 'next/server'
export async function GET(req: NextRequest) {
const { searchParams } = new URL(req.url)
const query = searchParams.get('search') // ✅ Match the client-side key
if (!query || query.length < 2) {
return NextResponse.json([], { status: 200 })
}
const results = await prisma.guestBookEntry.findMany({
where: {
OR: [
{ fName: { contains: query, mode: 'insensitive' } },
{ lName: { contains: query, mode: 'insensitive' } },
{ email: { contains: query, mode: 'insensitive' } },
]
},
orderBy: [
{ lName: 'asc' },
{ fName: 'asc' },
],
take: 10
})
return NextResponse.json(results)
}