V 1.2.1 Berechnugn der Resttsage auch beim Start

This commit is contained in:
rxf
2026-03-23 10:08:03 +01:00
parent 229cbf7223
commit 8bfc2b685b
2 changed files with 24 additions and 20 deletions

View File

@@ -5,6 +5,10 @@ import { checkAblauf } from '@/lib/checkAblauf';
import moment from 'moment';
import { Tablette, DataResponse } from '@/types/tablette';
// Verhindert Caching der Route
export const dynamic = 'force-dynamic';
export const revalidate = 0;
function formatDate(dt: Date | string | null): string {
if (!dt) return '';
const d = moment(dt);
@@ -24,22 +28,26 @@ export async function GET(req: NextRequest) {
try {
const [rows] = await pool.query<RowDataPacket[]>(
`SELECT tab, pday, cnt, at, akt, until, warn, rem, \`order\`
`SELECT tab, pday, cnt, at, rem, \`order\`
FROM tabletten
ORDER BY ${col} ${sord}, rem DESC, tab ASC`
);
const values: Tablette[] = rows.map((r) => ({
tab: r.tab,
pday: r.pday,
cnt: r.cnt,
at: formatDate(r.at),
akt: r.akt,
until: formatDate(r.until),
warn: r.warn === 1 || r.warn === true,
rem: r.rem,
order: r.order,
}));
const values: Tablette[] = rows.map((r) => {
// Berechne die aktuellen Werte dynamisch basierend auf dem heutigen Datum
const calculated = checkAblauf({ cnt: r.cnt, pday: r.pday, at: r.at });
return {
tab: r.tab,
pday: r.pday,
cnt: r.cnt,
at: formatDate(r.at),
akt: calculated.akt,
until: formatDate(calculated.until),
warn: calculated.warn,
rem: r.rem,
order: r.order,
};
});
const result: DataResponse = {
total: 1,