editing event data
This commit is contained in:
@@ -18,8 +18,8 @@ export default async function DashboardPage() {
|
||||
<p>Name: <strong>{item.name}</strong></p>
|
||||
<p>Date: {item.date ? item.date.toISOString() : 'null'}</p>
|
||||
<p>Location: {item.location ? item.location : 'null'}</p>
|
||||
<p>Creator ID:{item.creatorId}</p>
|
||||
<p>Created At:{item.createdAt.toISOString()}</p>
|
||||
<p>Created By: {item.creator.username}</p>
|
||||
<p>Created At: {item.createdAt.toISOString()}</p>
|
||||
|
||||
</div>
|
||||
</Link>
|
||||
|
||||
@@ -1,15 +1,24 @@
|
||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
import EventInfoDisplay from '@/components/EventInfoDisplay'
|
||||
import HeadingWithEdit from '@/components/HeadingWithEdit'
|
||||
import { queries } from '@/lib/queries'
|
||||
import React from 'react'
|
||||
|
||||
export default async function SingleEventPage({ params }: { params: { eventId: string }}) {
|
||||
console.log(params)
|
||||
const data = await queries.singleEvent(params.eventId)
|
||||
console.log(data)
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className='text-4xl font-bold'>
|
||||
{data?.name}
|
||||
</h1>
|
||||
{data ? (
|
||||
// @ts-ignore
|
||||
<EventInfoDisplay event={data} />
|
||||
) : (
|
||||
<p className="text-center text-gray-500 mt-10">Event not found.</p>
|
||||
)}
|
||||
{data?.name && (
|
||||
<HeadingWithEdit title={data?.name} eventId={data.id} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
22
app/api/events/[eventId]/route.ts
Normal file
22
app/api/events/[eventId]/route.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { mutations } from '@/lib/mutations';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '../../auth/[...nextauth]/route';
|
||||
|
||||
export async function PATCH(req: NextRequest, { params }: { params: { eventId: string } }) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) {
|
||||
return new NextResponse('Unauthorized', { status: 401 });
|
||||
}
|
||||
|
||||
const eventId = params.eventId;
|
||||
const body = await req.json();
|
||||
|
||||
try {
|
||||
const updated = await mutations.updateEvent(eventId, body);
|
||||
return NextResponse.json(updated);
|
||||
} catch (error) {
|
||||
console.error('[PATCH EVENT]', error);
|
||||
return new NextResponse('Failed to update event', { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user