import { NextRequest, NextResponse } from 'next/server'; import { query } from '@/lib/db'; import { CreateWerteEntry } from '@/types/werte'; const TABLE = 'RXF.Werte_BZG'; export async function PUT( request: NextRequest, context: { params: Promise<{ id: string }> } ) { try { const { id } = await context.params; const body: CreateWerteEntry = await request.json(); const sql = `UPDATE ${TABLE} SET Datum = ?, Zeit = ?, Zucker = ?, Essen = ?, Gewicht = ?, DruckS = ?, DruckD = ?, Puls = ? WHERE ID = ?`; const params = [ body.Datum, body.Zeit, body.Zucker || null, body.Essen || null, body.Gewicht ? parseFloat(parseFloat(String(body.Gewicht)).toFixed(1)) : null, body.DruckS || null, body.DruckD || null, body.Puls || null, parseInt(id, 10), ]; const result = await query(sql, params); return NextResponse.json({ success: true, data: result }); } catch (error) { console.error('Database error:', error); return NextResponse.json( { success: false, error: 'Failed to update entry' }, { status: 500 } ); } } export async function DELETE( request: NextRequest, context: { params: Promise<{ id: string }> } ) { try { const { id } = await context.params; const sql = `DELETE FROM ${TABLE} WHERE ID = ?`; const result = await query(sql, [parseInt(id, 10)]); return NextResponse.json({ success: true, data: result }); } catch (error) { console.error('Database error:', error); return NextResponse.json( { success: false, error: 'Failed to delete entry' }, { status: 500 } ); } }