a75303f857
- lib/db.ts entfernt, mysql2-Abhängigkeit gestrichen - lib/phpdb.ts: HTTP-Client für alle DB-Operationen via DB4js_all.php - Alle API-Routen und Server Actions auf phpdb.ts umgestellt - compose.yml / docker-compose.prod.yml: MySQL/phpMyAdmin-Container entfernt - app/api/DB4js_all.php/route.ts: Proxy für Statistik-AJAX-Calls - Statistik-Grafik liest ab 2026 live aus logbuch statt StatistikJahre - PHP 7.3-Kompatibilität: str_contains → strpos Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
57 lines
2.3 KiB
TypeScript
57 lines
2.3 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { getSession } from '@/lib/session';
|
|
import { triggerBackup } from '@/lib/backup';
|
|
import * as phpdb from '@/lib/phpdb';
|
|
|
|
export async function PUT(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
const session = await getSession();
|
|
if (!session) return NextResponse.json({ error: 'Nicht angemeldet' }, { status: 401 });
|
|
|
|
const { id } = await params;
|
|
const logbuchId = parseInt(id);
|
|
|
|
try {
|
|
const body = await request.json();
|
|
const { Kuppel, ArtFuehrung, SonderName, Beginn, Ende, Besucher, beoIds, objekte, Bemerkungen, Wetter } = body;
|
|
|
|
await phpdb.updateLogbuch(logbuchId, session.beoId, session.role ?? '', {
|
|
Kuppel, ArtFuehrung, SonderName, Beginn, Ende,
|
|
Besucher: Besucher ?? 0,
|
|
beoIds: beoIds ?? [],
|
|
objekte: objekte ?? [],
|
|
Bemerkungen: Bemerkungen ?? null,
|
|
Wetter: Wetter ?? null,
|
|
});
|
|
|
|
triggerBackup();
|
|
return NextResponse.json({ ok: true });
|
|
} catch (error: unknown) {
|
|
if (error instanceof Error) {
|
|
if (error.message.includes('404')) return NextResponse.json({ error: 'Eintrag nicht gefunden' }, { status: 404 });
|
|
if (error.message.includes('403')) return NextResponse.json({ error: 'Keine Berechtigung' }, { status: 403 });
|
|
}
|
|
console.error('PUT /api/logbuch/[id]:', error);
|
|
return NextResponse.json({ error: 'Datenbankfehler' }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function DELETE(_request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
const session = await getSession();
|
|
if (!session) return NextResponse.json({ error: 'Nicht angemeldet' }, { status: 401 });
|
|
|
|
const { id } = await params;
|
|
const logbuchId = parseInt(id);
|
|
|
|
try {
|
|
await phpdb.deleteLogbuch(logbuchId, session.beoId, session.role ?? '');
|
|
return NextResponse.json({ ok: true });
|
|
} catch (error: unknown) {
|
|
if (error instanceof Error) {
|
|
if (error.message.includes('404')) return NextResponse.json({ error: 'Eintrag nicht gefunden' }, { status: 404 });
|
|
if (error.message.includes('403')) return NextResponse.json({ error: 'Keine Berechtigung' }, { status: 403 });
|
|
}
|
|
console.error('DELETE /api/logbuch/[id]:', error);
|
|
return NextResponse.json({ error: 'Datenbankfehler' }, { status: 500 });
|
|
}
|
|
}
|