Aktueller Stand
This commit is contained in:
@@ -13,16 +13,76 @@ export async function PATCH(request: Request, context: { params: { id: string }
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const { status } = body || {};
|
||||
const {
|
||||
status,
|
||||
title,
|
||||
description,
|
||||
location,
|
||||
locationPlaceId,
|
||||
locationLat,
|
||||
locationLng,
|
||||
startAt,
|
||||
endAt,
|
||||
categoryId
|
||||
} = body || {};
|
||||
|
||||
if (!status || !["APPROVED", "REJECTED"].includes(status)) {
|
||||
return NextResponse.json({ error: "Status ungueltig." }, { status: 400 });
|
||||
if (status && ["APPROVED", "REJECTED"].includes(status)) {
|
||||
const event = await prisma.event.update({
|
||||
where: { id: context.params.id },
|
||||
data: { status }
|
||||
});
|
||||
|
||||
return NextResponse.json(event);
|
||||
}
|
||||
|
||||
if (!title || !startAt || !categoryId) {
|
||||
return NextResponse.json(
|
||||
{ error: "Titel, Start und Kategorie sind erforderlich." },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const startDate = new Date(startAt);
|
||||
const endDate = endAt ? new Date(endAt) : null;
|
||||
|
||||
const event = await prisma.event.update({
|
||||
where: { id: context.params.id },
|
||||
data: { status }
|
||||
data: {
|
||||
title,
|
||||
description: description || null,
|
||||
location: location || null,
|
||||
locationPlaceId: locationPlaceId || null,
|
||||
locationLat: locationLat ? Number(locationLat) : null,
|
||||
locationLng: locationLng ? Number(locationLng) : null,
|
||||
startAt: startDate,
|
||||
endAt: endDate,
|
||||
category: { connect: { id: categoryId } }
|
||||
}
|
||||
});
|
||||
|
||||
return NextResponse.json(event);
|
||||
}
|
||||
|
||||
export async function DELETE(
|
||||
_request: Request,
|
||||
context: { params: { id: string } }
|
||||
) {
|
||||
const { session } = await requireSession();
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
if (!isAdminSession(session)) {
|
||||
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
||||
}
|
||||
|
||||
await prisma.userViewItem.deleteMany({
|
||||
where: { eventId: context.params.id }
|
||||
});
|
||||
|
||||
await prisma.event.delete({
|
||||
where: { id: context.params.id }
|
||||
});
|
||||
|
||||
return NextResponse.json({ ok: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user