Files
myeasycms-v2/apps/web/app/api/club/contact/route.ts
T. Zehetbauer 7b078f298b
Some checks failed
Workflow / ʦ TypeScript (push) Failing after 4m50s
Workflow / ⚫️ Test (push) Has been skipped
feat: enhance API response handling and add new components for module management
2026-04-01 15:18:24 +02:00

55 lines
1.5 KiB
TypeScript

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 parsed = ContactSchema.safeParse(body);
if (!parsed.success) {
return apiError(parsed.error.issues[0]?.message ?? 'Ungültige Eingabe');
}
const { recipientEmail, name, email, subject, message } = parsed.data;
// In production: use @kit/mailers to send the email
// For now: log and return success
logger.info(
{
to: recipientEmail || 'admin',
from: email,
name,
subject: subject || 'Kontaktanfrage',
message,
},
'[contact] Form submission',
);
// TODO: Wire to @kit/mailers
// const mailer = await getMailer();
// await mailer.sendMail({
// to: recipientEmail,
// from: email,
// subject: subject || 'Kontaktanfrage von der Website',
// text: `Name: ${name}\nE-Mail: ${email}\n\n${message}`,
// });
return apiSuccess({ message: 'Nachricht gesendet' });
} catch (err) {
logger.error({ error: err, context: 'contact' }, '[contact] Error');
return apiError('Serverfehler', 500);
}
}