Aktueller Stand

This commit is contained in:
2026-01-15 16:24:09 +01:00
parent 5d2630a02f
commit 46eae2a2a9
70 changed files with 7866 additions and 447 deletions

View File

@@ -25,7 +25,8 @@ export async function GET(request: Request) {
const events = await prisma.event.findMany({
where,
orderBy: { startAt: "asc" }
orderBy: { startAt: "asc" },
include: { category: true }
});
return NextResponse.json(events);
@@ -38,24 +39,68 @@ export async function POST(request: Request) {
}
const body = await request.json();
const { title, description, location, startAt, endAt } = body || {};
const {
title,
description,
location,
locationPlaceId,
locationLat,
locationLng,
startAt,
endAt,
categoryId
} = body || {};
if (!title || !startAt || !endAt) {
if (!title || !startAt) {
return NextResponse.json(
{ error: "Titel, Start und Ende sind erforderlich." },
{ error: "Titel und Start sind erforderlich." },
{ status: 400 }
);
}
if (!categoryId) {
return NextResponse.json(
{ error: "Kategorie ist erforderlich." },
{ status: 400 }
);
}
const startDate = new Date(startAt);
const endDate = endAt
? new Date(endAt)
: new Date(startDate.getTime() + 3 * 60 * 60 * 1000);
const creatorEmail = session.user?.email || "";
const existing = await prisma.event.findFirst({
where: {
title,
startAt: startDate,
location: location || null,
categoryId,
createdBy: { email: creatorEmail }
}
});
if (existing) {
return NextResponse.json(
{ error: "Ein identischer Termin existiert bereits." },
{ status: 409 }
);
}
const event = await prisma.event.create({
data: {
title,
description: description || null,
location: location || null,
startAt: new Date(startAt),
endAt: new Date(endAt),
locationPlaceId: locationPlaceId || null,
locationLat: locationLat ? Number(locationLat) : null,
locationLng: locationLng ? Number(locationLng) : null,
startAt: startDate,
endAt: endDate,
status: isAdminSession(session) ? "APPROVED" : "PENDING",
createdBy: { connect: { email: session.user?.email || "" } }
createdBy: { connect: { email: creatorEmail } },
category: { connect: { id: categoryId } }
}
});