logic for eventGuests
This commit is contained in:
18
app/api/events/[eventId]/guests/[entryId]/route.ts
Normal file
18
app/api/events/[eventId]/guests/[entryId]/route.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { mutations } from '@/lib/mutations'
|
||||
|
||||
export async function DELETE(_: Request, { params }: { params: { eventId: string; entryId: string } }) {
|
||||
const { eventId, entryId: guestBookEntryId } = params
|
||||
|
||||
if (!eventId || !guestBookEntryId) {
|
||||
return NextResponse.json({ message: 'Missing eventId or guestBookEntryId' }, { status: 400 })
|
||||
}
|
||||
|
||||
try {
|
||||
await mutations.removeEventGuest(eventId, guestBookEntryId)
|
||||
return NextResponse.json({ success: true })
|
||||
} catch (error) {
|
||||
console.error('Remove Guest Error:', error)
|
||||
return NextResponse.json({ message: 'Failed to remove guest from event' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
20
app/api/events/[eventId]/guests/[entryId]/rsvp/route.ts
Normal file
20
app/api/events/[eventId]/guests/[entryId]/rsvp/route.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
// app/api/events/[eventId]/guests/[entryId]/rsvp/route.ts
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { mutations } from '@/lib/mutations'
|
||||
|
||||
export async function PATCH(req: NextRequest, { params }: { params: { eventId: string; entryId: string } }) {
|
||||
const { eventId, entryId: guestBookEntryId } = params
|
||||
const { rsvp } = await req.json()
|
||||
|
||||
if (!['YES', 'NO', 'PENDING'].includes(rsvp)) {
|
||||
return NextResponse.json({ message: 'Invalid RSVP status' }, { status: 400 })
|
||||
}
|
||||
|
||||
try {
|
||||
const updated = await mutations.updateEventGuestRsvp({ eventId, guestBookEntryId, rsvp })
|
||||
return NextResponse.json(updated)
|
||||
} catch (error) {
|
||||
console.error('RSVP Update Error:', error)
|
||||
return NextResponse.json({ message: 'Failed to update RSVP status' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
19
app/api/events/[eventId]/guests/add/route.ts
Normal file
19
app/api/events/[eventId]/guests/add/route.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { mutations } from '@/lib/mutations'
|
||||
|
||||
export async function POST(req: NextRequest, { params }: { params: { eventId: string } }) {
|
||||
const eventId = params.eventId
|
||||
const { guestBookEntryId } = await req.json()
|
||||
|
||||
if (!eventId || !guestBookEntryId) {
|
||||
return NextResponse.json({ message: 'Missing eventId or guestBookEntryId' }, { status: 400 })
|
||||
}
|
||||
|
||||
try {
|
||||
const added = await mutations.addEventGuest({ eventId, guestBookEntryId })
|
||||
return NextResponse.json(added)
|
||||
} catch (error) {
|
||||
console.error('Add Event Guest Error:', error)
|
||||
return NextResponse.json({ message: 'Failed to add guest to event' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user