fix(api): /v1/me/tasks query — completedAt-based window + iso cast
Some checks failed
CI / Lint (push) Has been cancelled
CI / Typecheck (push) Has been cancelled
CI / Broker tests (Postgres) (push) Has been cancelled
CI / Docker build (linux/amd64) (push) Has been cancelled

the previous form had drizzle render the date param as a js
toString() value which postgres rejected (Fri Apr 03 2026
GMT+0000 doesn't parse as timestamp without help). fix:
serialize to iso then cast ::timestamp inside the sql tag.

simplified the where clause too — the prior conditional dance
emitted "status != completed" three times redundantly. one
"completed_at IS NULL OR > window" covers active + recent-done
in one clause; status filtering happens client-side via the
existing statusSet pass.

also cleans up the debug probe scaffolding.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Alejandro Gutiérrez
2026-05-03 10:29:13 +01:00
parent f679b49b6c
commit 4b459622e4

View File

@@ -953,7 +953,9 @@ export const v1Router = new Hono<Env>()
? new Set(["open", "claimed"])
: new Set(statusFilter.split(",").map((s) => s.trim()));
const completedWindow = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
const completedWindowIso = new Date(
Date.now() - 30 * 24 * 60 * 60 * 1000,
).toISOString();
const rows = await db
.select({
id: meshTask.id,
@@ -974,18 +976,14 @@ export const v1Router = new Hono<Env>()
.where(
and(
inArray(meshTask.meshId, meshIds),
// Bound the completed-task scan; open/claimed have no time filter.
...(statusSet === null || statusSet.has("completed")
? []
: [sql`${meshTask.status} != 'completed'`]),
...(statusFilter === "active"
? [sql`${meshTask.status} != 'completed'`]
: []),
// Hide stale completed tasks beyond the window unless explicitly all.
// For "active" (default) and any non-"all" status filter:
// hide completed tasks older than 30 days. completedAt is
// null on open/claimed, so "completed_at IS NULL OR > window"
// keeps everything non-completed plus recent completions.
...(statusFilter === "all"
? []
: [
sql`(${meshTask.status} != 'completed' OR ${meshTask.completedAt} > ${completedWindow})`,
sql`(${meshTask.completedAt} IS NULL OR ${meshTask.completedAt} > ${completedWindowIso}::timestamp)`,
]),
),
)