fix: align moments range and failed filter
This commit is contained in:
@@ -9,6 +9,7 @@ const querySchema = z
|
|||||||
.object({
|
.object({
|
||||||
start: z.string().datetime().optional(),
|
start: z.string().datetime().optional(),
|
||||||
end: 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),
|
limit: z.coerce.number().int().positive().max(2000).default(1000),
|
||||||
})
|
})
|
||||||
.strict();
|
.strict();
|
||||||
@@ -18,6 +19,7 @@ export async function GET(request: Request): Promise<Response> {
|
|||||||
const parsed = querySchema.safeParse({
|
const parsed = querySchema.safeParse({
|
||||||
start: url.searchParams.get("start") ?? undefined,
|
start: url.searchParams.get("start") ?? undefined,
|
||||||
end: url.searchParams.get("end") ?? undefined,
|
end: url.searchParams.get("end") ?? undefined,
|
||||||
|
includeFailed: url.searchParams.get("includeFailed") ?? undefined,
|
||||||
limit: url.searchParams.get("limit") ?? undefined,
|
limit: url.searchParams.get("limit") ?? undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -31,6 +33,7 @@ export async function GET(request: Request): Promise<Response> {
|
|||||||
const query = parsed.data;
|
const query = parsed.data;
|
||||||
const start = query.start ? new Date(query.start) : null;
|
const start = query.start ? new Date(query.start) : null;
|
||||||
const end = query.end ? new Date(query.end) : null;
|
const end = query.end ? new Date(query.end) : null;
|
||||||
|
const includeFailed = query.includeFailed === 1;
|
||||||
|
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
const rows = await db<
|
const rows = await db<
|
||||||
@@ -44,7 +47,7 @@ export async function GET(request: Request): Promise<Response> {
|
|||||||
where capture_ts_utc is not null
|
where capture_ts_utc is not null
|
||||||
and (${start}::timestamptz is null or capture_ts_utc >= ${start}::timestamptz)
|
and (${start}::timestamptz is null or capture_ts_utc >= ${start}::timestamptz)
|
||||||
and (${end}::timestamptz is null or capture_ts_utc < ${end}::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
|
order by capture_ts_utc asc, id asc
|
||||||
limit ${query.limit}
|
limit ${query.limit}
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -204,10 +204,14 @@ export function TimelineTree(props: {
|
|||||||
setMomentsError(null);
|
setMomentsError(null);
|
||||||
if (!rows || rows.length === 0) return;
|
if (!rows || rows.length === 0) return;
|
||||||
const start = rows[0]?.group_ts ?? null;
|
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();
|
const params = new URLSearchParams();
|
||||||
if (start) params.set("start", start);
|
if (start) params.set("start", start);
|
||||||
if (end) params.set("end", end);
|
if (end) params.set("end", end);
|
||||||
|
params.set("includeFailed", "1");
|
||||||
const res = await fetch(`/api/moments?${params.toString()}`, {
|
const res = await fetch(`/api/moments?${params.toString()}`, {
|
||||||
cache: "no-store",
|
cache: "no-store",
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user