Files
werte-next/app/api/werte/[id]/route.ts
2026-02-22 22:11:52 +01:00

57 lines
1.6 KiB
TypeScript

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 = '${body.Datum}',
Zeit = '${body.Zeit}',
Zucker = ${body.Zucker || 'NULL'},
Essen = ${body.Essen ? `'${body.Essen.replace(/'/g, "''")}'` : 'NULL'},
Gewicht = ${body.Gewicht || 'NULL'},
DruckS = ${body.DruckS || 'NULL'},
DruckD = ${body.DruckD || 'NULL'},
Puls = ${body.Puls || 'NULL'}
WHERE ID = ${parseInt(id, 10)}`;
const result = await query(sql);
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 = ${parseInt(id, 10)}`;
const result = await query(sql);
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 }
);
}
}