feat: due dates, subtasks, and task detail page (HQ-{number} URLs)
- Schema: added due_date and subtasks JSONB columns to tasks
- API: CRUD endpoints for subtasks (/tasks/:id/subtasks)
- API: due date support in create/update task
- TaskDetailPanel: due date picker with overdue/soon badges
- TaskDetailPanel: subtask checklist with progress bar
- TaskPage: full-page task view at /task/HQ-{number}
- Dashboard: task cards link to detail page, show subtask progress & due date badges
- Migration: 0001_mighty_callisto.sql
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Elysia, t } from "elysia";
|
||||
import { db } from "../db";
|
||||
import { tasks, type ProgressNote } from "../db/schema";
|
||||
import { tasks, type ProgressNote, type Subtask } from "../db/schema";
|
||||
import { eq, asc, desc, sql, inArray, or } from "drizzle-orm";
|
||||
import { auth } from "../lib/auth";
|
||||
|
||||
@@ -153,6 +153,8 @@ export const taskRoutes = new Elysia({ prefix: "/api/tasks" })
|
||||
position: (maxPos[0]?.max ?? 0) + 1,
|
||||
taskNumber: nextNumber,
|
||||
projectId: body.projectId || null,
|
||||
dueDate: body.dueDate ? new Date(body.dueDate) : null,
|
||||
subtasks: [],
|
||||
progressNotes: [],
|
||||
})
|
||||
.returning();
|
||||
@@ -190,6 +192,7 @@ export const taskRoutes = new Elysia({ prefix: "/api/tasks" })
|
||||
])
|
||||
),
|
||||
projectId: t.Optional(t.Union([t.String(), t.Null()])),
|
||||
dueDate: t.Optional(t.Union([t.String(), t.Null()])),
|
||||
}),
|
||||
}
|
||||
)
|
||||
@@ -236,6 +239,8 @@ export const taskRoutes = new Elysia({ prefix: "/api/tasks" })
|
||||
if (body.assigneeId !== undefined) updates.assigneeId = body.assigneeId;
|
||||
if (body.assigneeName !== undefined) updates.assigneeName = body.assigneeName;
|
||||
if (body.projectId !== undefined) updates.projectId = body.projectId;
|
||||
if (body.dueDate !== undefined) updates.dueDate = body.dueDate ? new Date(body.dueDate) : null;
|
||||
if (body.subtasks !== undefined) updates.subtasks = body.subtasks;
|
||||
|
||||
const updated = await db
|
||||
.update(tasks)
|
||||
@@ -263,10 +268,107 @@ export const taskRoutes = new Elysia({ prefix: "/api/tasks" })
|
||||
assigneeId: t.Optional(t.Union([t.String(), t.Null()])),
|
||||
assigneeName: t.Optional(t.Union([t.String(), t.Null()])),
|
||||
projectId: t.Optional(t.Union([t.String(), t.Null()])),
|
||||
dueDate: t.Optional(t.Union([t.String(), t.Null()])),
|
||||
subtasks: t.Optional(t.Array(t.Object({
|
||||
id: t.String(),
|
||||
title: t.String(),
|
||||
completed: t.Boolean(),
|
||||
completedAt: t.Optional(t.String()),
|
||||
createdAt: t.String(),
|
||||
}))),
|
||||
}),
|
||||
}
|
||||
)
|
||||
|
||||
// POST add subtask - requires auth
|
||||
.post(
|
||||
"/:id/subtasks",
|
||||
async ({ params, body, request, headers }) => {
|
||||
await requireSessionOrBearer(request, headers);
|
||||
const task = await resolveTask(params.id);
|
||||
if (!task) throw new Error("Task not found");
|
||||
|
||||
const currentSubtasks = (task.subtasks || []) as Subtask[];
|
||||
const newSubtask: Subtask = {
|
||||
id: `st-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
|
||||
title: body.title,
|
||||
completed: false,
|
||||
createdAt: new Date().toISOString(),
|
||||
};
|
||||
currentSubtasks.push(newSubtask);
|
||||
|
||||
const updated = await db
|
||||
.update(tasks)
|
||||
.set({ subtasks: currentSubtasks, updatedAt: new Date() })
|
||||
.where(eq(tasks.id, task.id))
|
||||
.returning();
|
||||
return updated[0];
|
||||
},
|
||||
{
|
||||
params: t.Object({ id: t.String() }),
|
||||
body: t.Object({ title: t.String() }),
|
||||
}
|
||||
)
|
||||
|
||||
// PATCH toggle subtask - requires auth
|
||||
.patch(
|
||||
"/:id/subtasks/:subtaskId",
|
||||
async ({ params, body, request, headers }) => {
|
||||
await requireSessionOrBearer(request, headers);
|
||||
const task = await resolveTask(params.id);
|
||||
if (!task) throw new Error("Task not found");
|
||||
|
||||
const currentSubtasks = (task.subtasks || []) as Subtask[];
|
||||
const subtask = currentSubtasks.find((s) => s.id === params.subtaskId);
|
||||
if (!subtask) throw new Error("Task not found");
|
||||
|
||||
if (body.completed !== undefined) {
|
||||
subtask.completed = body.completed;
|
||||
subtask.completedAt = body.completed ? new Date().toISOString() : undefined;
|
||||
}
|
||||
if (body.title !== undefined) {
|
||||
subtask.title = body.title;
|
||||
}
|
||||
|
||||
const updated = await db
|
||||
.update(tasks)
|
||||
.set({ subtasks: currentSubtasks, updatedAt: new Date() })
|
||||
.where(eq(tasks.id, task.id))
|
||||
.returning();
|
||||
return updated[0];
|
||||
},
|
||||
{
|
||||
params: t.Object({ id: t.String(), subtaskId: t.String() }),
|
||||
body: t.Object({
|
||||
completed: t.Optional(t.Boolean()),
|
||||
title: t.Optional(t.String()),
|
||||
}),
|
||||
}
|
||||
)
|
||||
|
||||
// DELETE subtask - requires auth
|
||||
.delete(
|
||||
"/:id/subtasks/:subtaskId",
|
||||
async ({ params, request, headers }) => {
|
||||
await requireSessionOrBearer(request, headers);
|
||||
const task = await resolveTask(params.id);
|
||||
if (!task) throw new Error("Task not found");
|
||||
|
||||
const currentSubtasks = (task.subtasks || []) as Subtask[];
|
||||
const filtered = currentSubtasks.filter((s) => s.id !== params.subtaskId);
|
||||
|
||||
const updated = await db
|
||||
.update(tasks)
|
||||
.set({ subtasks: filtered, updatedAt: new Date() })
|
||||
.where(eq(tasks.id, task.id))
|
||||
.returning();
|
||||
return updated[0];
|
||||
},
|
||||
{
|
||||
params: t.Object({ id: t.String(), subtaskId: t.String() }),
|
||||
}
|
||||
)
|
||||
|
||||
// POST add progress note - requires auth
|
||||
.post(
|
||||
"/:id/notes",
|
||||
|
||||
Reference in New Issue
Block a user