From d93caedb3105f512c042e024c1814795aa3e25dc Mon Sep 17 00:00:00 2001 From: William Valentin Date: Thu, 5 Feb 2026 09:17:16 -0800 Subject: [PATCH] fix: align moments range and failed filter --- apps/web/app/api/moments/route.ts | 5 ++++- apps/web/app/components/TimelineTree.tsx | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/web/app/api/moments/route.ts b/apps/web/app/api/moments/route.ts index cb0f65d..0604655 100644 --- a/apps/web/app/api/moments/route.ts +++ b/apps/web/app/api/moments/route.ts @@ -9,6 +9,7 @@ const querySchema = z .object({ start: z.string().datetime().optional(), end: z.string().datetime().optional(), + includeFailed: z.coerce.number().int().optional(), limit: z.coerce.number().int().positive().max(2000).default(1000), }) .strict(); @@ -18,6 +19,7 @@ export async function GET(request: Request): Promise { const parsed = querySchema.safeParse({ start: url.searchParams.get("start") ?? undefined, end: url.searchParams.get("end") ?? undefined, + includeFailed: url.searchParams.get("includeFailed") ?? undefined, limit: url.searchParams.get("limit") ?? undefined, }); @@ -31,6 +33,7 @@ export async function GET(request: Request): Promise { const query = parsed.data; const start = query.start ? new Date(query.start) : null; const end = query.end ? new Date(query.end) : null; + const includeFailed = query.includeFailed === 1; const db = getDb(); const rows = await db< @@ -44,7 +47,7 @@ export async function GET(request: Request): Promise { where capture_ts_utc is not null and (${start}::timestamptz is null or capture_ts_utc >= ${start}::timestamptz) and (${end}::timestamptz is null or capture_ts_utc < ${end}::timestamptz) - and status <> 'failed' + and (${includeFailed}::boolean is true or status <> 'failed') order by capture_ts_utc asc, id asc limit ${query.limit} `; diff --git a/apps/web/app/components/TimelineTree.tsx b/apps/web/app/components/TimelineTree.tsx index 8310628..fee8267 100644 --- a/apps/web/app/components/TimelineTree.tsx +++ b/apps/web/app/components/TimelineTree.tsx @@ -204,10 +204,14 @@ export function TimelineTree(props: { setMomentsError(null); if (!rows || rows.length === 0) return; const start = rows[0]?.group_ts ?? null; - const end = rows[rows.length - 1]?.group_ts ?? null; + const last = rows[rows.length - 1]?.group_ts ?? null; + const end = last + ? new Date(new Date(last).getTime() + 24 * 60 * 60 * 1000).toISOString() + : null; const params = new URLSearchParams(); if (start) params.set("start", start); if (end) params.set("end", end); + params.set("includeFailed", "1"); const res = await fetch(`/api/moments?${params.toString()}`, { cache: "no-store", });