feat: enhance API response handling and add new components for module management
Some checks failed
Workflow / ʦ TypeScript (push) Failing after 4m50s
Workflow / ⚫️ Test (push) Has been skipped

This commit is contained in:
T. Zehetbauer
2026-04-01 15:18:24 +02:00
parent f82a366a52
commit 7b078f298b
58 changed files with 1845 additions and 398 deletions

View File

@@ -1,27 +1,28 @@
import { NextResponse } from 'next/server';
import * as z from 'zod';
import { apiError, apiSuccess, emailSchema } from '@kit/next/route-helpers';
import { getLogger } from '@kit/shared/logger';
const ContactSchema = z.object({
recipientEmail: z.string().optional(),
name: z.string().optional(),
email: emailSchema,
subject: z.string().optional(),
message: z.string().min(1, 'Nachricht ist erforderlich'),
});
export async function POST(request: Request) {
const logger = await getLogger();
try {
const body = await request.json();
const { recipientEmail, name, email, subject, message } = body;
const parsed = ContactSchema.safeParse(body);
if (!email || !message) {
return NextResponse.json(
{ error: 'E-Mail und Nachricht sind erforderlich' },
{ status: 400 },
);
if (!parsed.success) {
return apiError(parsed.error.issues[0]?.message ?? 'Ungültige Eingabe');
}
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
return NextResponse.json(
{ error: 'Ungültige E-Mail-Adresse' },
{ status: 400 },
);
}
const { recipientEmail, name, email, subject, message } = parsed.data;
// In production: use @kit/mailers to send the email
// For now: log and return success
@@ -45,9 +46,9 @@ export async function POST(request: Request) {
// text: `Name: ${name}\nE-Mail: ${email}\n\n${message}`,
// });
return NextResponse.json({ success: true, message: 'Nachricht gesendet' });
return apiSuccess({ message: 'Nachricht gesendet' });
} catch (err) {
logger.error({ error: err, context: 'contact' }, '[contact] Error');
return NextResponse.json({ error: 'Serverfehler' }, { status: 500 });
return apiError('Serverfehler', 500);
}
}