für Docker angepasst

This commit is contained in:
rxf
2026-02-22 22:11:52 +01:00
parent e14af11e5c
commit e28cca1c46
21 changed files with 1494 additions and 94 deletions

View File

@@ -0,0 +1,56 @@
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 }
);
}
}

63
app/api/werte/route.ts Normal file
View File

@@ -0,0 +1,63 @@
import { NextRequest, NextResponse } from 'next/server';
import { query } from '@/lib/db';
import { CreateWerteEntry } from '@/types/werte';
const TABLE = 'RXF.Werte_BZG';
// GET - Fetch entries
export async function GET(request: NextRequest) {
try {
const searchParams = request.nextUrl.searchParams;
const limit = parseInt(searchParams.get('limit') || '10', 10);
const sql = `SELECT ID, DATE_FORMAT(Datum, '%Y-%m-%d') as Datum, Zeit, Zucker, Essen, Gewicht, DruckD, DruckS, Puls FROM ${TABLE} ORDER BY Datum DESC, Zeit DESC LIMIT ${limit}`;
const rows = await query(sql);
return NextResponse.json(
{ success: true, data: rows },
{
headers: {
'Cache-Control': 'no-store, no-cache, must-revalidate',
'Pragma': 'no-cache',
'Expires': '0',
},
}
);
} catch (error) {
console.error('Database error:', error);
return NextResponse.json(
{ success: false, error: 'Failed to fetch entries' },
{ status: 500 }
);
}
}
// POST - Create new entry
export async function POST(request: NextRequest) {
try {
const body: CreateWerteEntry = await request.json();
const sql = `INSERT INTO ${TABLE} (Datum, Zeit, Zucker, Essen, Gewicht, DruckS, DruckD, Puls) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`;
const params = [
body.Datum,
body.Zeit,
body.Zucker || null,
body.Essen || null,
body.Gewicht || null,
body.DruckS || null,
body.DruckD || null,
body.Puls || null,
];
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 create entry' },
{ status: 500 }
);
}
}