venues and ui changes
This commit is contained in:
@@ -1,27 +1,29 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { mutations } from '@/lib/mutations';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '../../auth/[...nextauth]/route';
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { getServerSession } from 'next-auth'
|
||||
import { authOptions } from '@/app/api/auth/[...nextauth]/route'
|
||||
|
||||
export async function PATCH(req: NextRequest, { params }: { params: { eventId: string } }) {
|
||||
const session = await getServerSession(authOptions);
|
||||
const session = await getServerSession(authOptions)
|
||||
if (!session?.user) {
|
||||
return new NextResponse('Unauthorized', { status: 401 });
|
||||
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
const eventId = params.eventId;
|
||||
const body = await req.json();
|
||||
const body = await req.json()
|
||||
|
||||
try {
|
||||
const updated = await mutations.updateEvent(eventId, {
|
||||
name: body.name,
|
||||
date: body.date,
|
||||
location: body.location,
|
||||
notes: body.notes,
|
||||
});
|
||||
return NextResponse.json(updated);
|
||||
} catch (error) {
|
||||
console.error('[PATCH EVENT]', error);
|
||||
return new NextResponse('Failed to update event', { status: 500 });
|
||||
const updated = await prisma.event.update({
|
||||
where: { id: params.eventId },
|
||||
data: {
|
||||
name: body.name,
|
||||
date: body.date ? new Date(body.date) : undefined,
|
||||
venueId: body.venueId || null,
|
||||
},
|
||||
})
|
||||
|
||||
return NextResponse.json(updated)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
return NextResponse.json({ message: 'Error updating event' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user