fix: task-4 review round 1 (soon-constant, computed status, id guard)

This commit is contained in:
opencode committed 2026-10-18 10:31:48 +02:00
1 parent 660d6cff51
commit c86ec8bd36
5 files changed
+21 -18

No files matched your search

+2 -5
View File
@@ -2,7 +2,7 @@ import Link from "next/link";
import { Suspense } from "react";
import { getDb } from "@/lib/db";
import { getVoucherStatus } from "@/lib/voucher-status";
import { formatEuro } from "@/lib/vouchers";
import { formatEuro, isExpiringSoon } from "@/lib/vouchers";
const FILTERS = [
{ key: "", label: "Alle" },
@@ -28,14 +28,11 @@ function Skeleton() {
async function VoucherList({ filter }: { filter: string }) {
const db = getDb();
const all = await db.voucher.findMany({ orderBy: { createdAt: "desc" } });
const now = Date.now();
const in14d = now + 14 * 24 * 3600 * 1000;
const filtered = all.filter((v) => {
const s = getVoucherStatus(v);
if (filter === "eingeloest") return s === "eingeloest";
if (filter === "abgelaufen") return s === "abgelaufen";
if (filter === "bald")
return s === "aktiv" && v.ablaufdatum && +new Date(v.ablaufdatum) >= now && +new Date(v.ablaufdatum) <= in14d;
if (filter === "bald") return s === "aktiv" && isExpiringSoon(v.ablaufdatum);
if (filter === "aktiv") return s === "aktiv";
return true;
});