Initial commit: Kalendartool (Next.js, Prisma, Docker)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
45
app/api/invites/[token]/route.ts
Normal file
45
app/api/invites/[token]/route.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* GET /api/invites/[token] - Invite-Informationen fuer die
|
||||
* Annahme-Seite: "Du wurdest zum Kalender X eingeladen."
|
||||
*
|
||||
* Oeffentlich zugaenglich (vor der Registrierung), gibt aber nur
|
||||
* den Kalendertitel preis - niemals Reservierungen oder Mitglieder.
|
||||
*/
|
||||
import { NextResponse } from 'next/server';
|
||||
import { prisma } from '@/lib/db/client';
|
||||
import { hashInviteToken, isInviteUsable } from '@/lib/invites/tokens';
|
||||
import { errorResponse, notFoundResponse } from '@/lib/api/responses';
|
||||
|
||||
interface RouteParams {
|
||||
params: Promise<{ token: string }>;
|
||||
}
|
||||
|
||||
export async function GET(
|
||||
_request: Request,
|
||||
{ params }: RouteParams,
|
||||
): Promise<NextResponse> {
|
||||
try {
|
||||
const { token } = await params;
|
||||
const tokenHash = hashInviteToken(token);
|
||||
|
||||
const invite = await prisma.invite.findUnique({
|
||||
where: { tokenHash },
|
||||
select: {
|
||||
expiresAt: true,
|
||||
usedAt: true,
|
||||
calendar: { select: { title: true, description: true } },
|
||||
},
|
||||
});
|
||||
|
||||
if (!invite || !isInviteUsable(invite)) {
|
||||
return notFoundResponse('Dieser Einladungslink ist ungueltig oder abgelaufen.');
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
calendarTitle: invite.calendar.title,
|
||||
calendarDescription: invite.calendar.description,
|
||||
});
|
||||
} catch (error) {
|
||||
return errorResponse(error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user