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