Complete rebuild of 22-year-old PHP CMS as modern SaaS: Database (15 migrations, 42+ tables): - Foundation: account_settings, audit_log, GDPR register, cms_files - Module Engine: modules, fields, records, permissions, relations + RPC - Members: 45+ field member profiles, departments, roles, honors, SEPA mandates - Courses: courses, sessions, categories, instructors, locations, attendance - Bookings: rooms, guests, bookings with availability - Events: events, registrations, holiday passes - Finance: SEPA batches/items (pain.008/001 XML), invoices - Newsletter: campaigns, templates, recipients, subscriptions - Site Builder: site_pages (Puck JSON), site_settings, cms_posts - Portal Auth: member_portal_invitations, user linking Feature Packages (9): - @kit/module-builder — dynamic low-code CRUD engine - @kit/member-management — 31 API methods, 21 actions, 8 components - @kit/course-management, @kit/booking-management, @kit/event-management - @kit/finance — SEPA XML generator + IBAN validator - @kit/newsletter — campaigns + dispatch - @kit/document-generator — PDF/Excel/Word - @kit/site-builder — Puck visual editor, 15 blocks, public rendering Pages (60+): - Dashboard with real stats from all APIs - Full CRUD for all 8 domains with react-hook-form + Zod - Recharts statistics - German i18n throughout - Member portal with auth + invitation system - Public club websites via Puck at /club/[slug] Infrastructure: - Dockerfile (multi-stage, standalone output) - docker-compose.yml (Supabase self-hosted + Next.js) - Kong API gateway config - .env.production.example
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { createClient } from '@supabase/supabase-js';
|
|
import { NextResponse } from 'next/server';
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const body = await request.json();
|
|
const { accountId, email, name } = body;
|
|
|
|
if (!accountId || !email) {
|
|
return NextResponse.json({ error: 'accountId und email sind erforderlich' }, { status: 400 });
|
|
}
|
|
|
|
// Validate email format
|
|
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
|
return NextResponse.json({ error: 'Ungültige E-Mail-Adresse' }, { status: 400 });
|
|
}
|
|
|
|
const supabase = createClient(
|
|
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_PUBLIC_KEY!,
|
|
);
|
|
|
|
const token = crypto.randomUUID();
|
|
const { error } = await supabase.from('newsletter_subscriptions').upsert({
|
|
account_id: accountId,
|
|
email,
|
|
name: name || null,
|
|
confirmation_token: token,
|
|
is_active: true,
|
|
}, { onConflict: 'account_id,email' });
|
|
|
|
if (error) {
|
|
console.error('[newsletter] Subscription error:', error.message);
|
|
return NextResponse.json({ error: 'Anmeldung fehlgeschlagen' }, { status: 500 });
|
|
}
|
|
|
|
return NextResponse.json({ success: true, message: 'Erfolgreich angemeldet' });
|
|
} catch (err) {
|
|
console.error('[newsletter] Error:', err);
|
|
return NextResponse.json({ error: 'Serverfehler' }, { status: 500 });
|
|
}
|
|
}
|