import { NextResponse } from 'next/server'; import { getDbPool } from '@/lib/db'; import { ResultSetHeader } from 'mysql2'; // PUT /api/ausgaben/[id] - Update entry export async function PUT( request: Request, context: { params: Promise<{ id: string }> } ) { try { const { id } = await context.params; const body = await request.json(); const { Datum, WochTag, Wo, Was, Wieviel, Wie, OK } = body; const pool = getDbPool(); const query = ` UPDATE Ausgaben SET Datum = ?, WochTag = ?, Wo = ?, Was = ?, Wieviel = ?, Wie = ?, OK = ? WHERE ID = ? `; const [result] = await pool.query(query, [ Datum, WochTag, Wo, Was, parseFloat(Wieviel), Wie, OK || 0, parseInt(id), ]); if (result.affectedRows === 0) { return NextResponse.json( { success: false, error: 'Entry not found' }, { status: 404 } ); } return NextResponse.json({ success: true, }); } catch (error) { console.error('Database error:', error); return NextResponse.json( { success: false, error: 'Database error' }, { status: 500 } ); } } // DELETE /api/ausgaben/[id] - Delete entry export async function DELETE( request: Request, context: { params: Promise<{ id: string }> } ) { try { const { id } = await context.params; const pool = getDbPool(); const query = 'DELETE FROM Ausgaben WHERE ID = ?'; const [result] = await pool.query(query, [parseInt(id)]); if (result.affectedRows === 0) { return NextResponse.json( { success: false, error: 'Entry not found' }, { status: 404 } ); } return NextResponse.json({ success: true, }); } catch (error) { console.error('Database error:', error); return NextResponse.json( { success: false, error: 'Database error' }, { status: 500 } ); } }