A To do card on server pages and in a device's drawer

- The open jobs about a server (or device) are listed on its page, with a line to add another already about it and a box to tick one off with Undo
- GET /api/todos takes ?targetType=&targetId= to list only those about one thing
- README and ROLES updated

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-20 22:46:12 +02:00
1 parent 18ceed62e8
commit 788b3e073c
10 files changed
+164 -9

No files matched your search

+5 -2
View File
@@ -22,8 +22,11 @@ const fields = {
targetId: z.number().int().positive().nullable().optional(),
};
todosRouter.get("/", asyncHandler(async (_req, res) => {
res.json({ todos: await listTodos(), people: await assignableUsers() });
// `?targetType=server&targetId=3` lists only the jobs about that one (a server's page shows its own).
todosRouter.get("/", asyncHandler(async (req, res) => {
const type = TARGET_TYPES.find((t) => t === req.query.targetType);
const id = /^\d+$/.test(String(req.query.targetId ?? "")) ? Number(req.query.targetId) : NaN;
res.json({ todos: await listTodos(type && Number.isInteger(id) ? { type, id } : undefined), people: await assignableUsers() });
}));
todosRouter.post("/", requireRole("operator"), asyncHandler(async (req, res) => {
+4 -3
View File
@@ -68,10 +68,11 @@ async function shape(rows: Row[]): Promise<TodoItem[]> {
}
/** Open ones first, the soonest due first (those with no day last); done ones after, the latest done first. */
export async function listTodos(): Promise<TodoItem[]> {
const open = await shape(await db.select().from(todos).where(isNull(todos.doneAt)));
export async function listTodos(about?: { type: TargetType; id: number }): Promise<TodoItem[]> {
const only = about ? and(eq(todos.targetType, about.type), eq(todos.targetId, about.id)) : undefined;
const open = await shape(await db.select().from(todos).where(and(isNull(todos.doneAt), only)));
open.sort((a, b) => (a.dueDate ?? "9999-99-99").localeCompare(b.dueDate ?? "9999-99-99") || a.createdAt.localeCompare(b.createdAt) || a.id - b.id);
const done = await shape(await db.select().from(todos).where(isNotNull(todos.doneAt)).orderBy(desc(todos.doneAt)).limit(200));
const done = await shape(await db.select().from(todos).where(and(isNotNull(todos.doneAt), only)).orderBy(desc(todos.doneAt)).limit(200));
return [...open, ...done];
}
+7
View File
@@ -115,6 +115,13 @@ describe("the to-do list", () => {
assert.equal(back.body.todo.doneAt, null);
});
test("a server's page asks for just the jobs about it", async () => {
const mine = (await send("GET", `/todos?targetType=server&targetId=${ids.web}`)).body.todos.map((t: any) => t.title);
assert.deepEqual(mine, ["Replace the UPS battery"], "the two with nothing to do with it are left out");
assert.equal((await send("GET", `/todos?targetType=server&targetId=999999`)).body.todos.length, 0);
assert.equal((await send("GET", `/todos?targetType=bogus&targetId=${ids.web}`)).body.todos.length >= 3, true, "an unknown kind is no filter");
});
test("a job can be changed, and removed; one that is not there is a 404", async () => {
const changed = await send("PATCH", `/todos/${jobId}`, { title: "Replace the UPS battery (APC)", dueDate: null, assigneeId: null });
assert.deepEqual([changed.body.todo.title, changed.body.todo.dueDate, changed.body.todo.assignee], ["Replace the UPS battery (APC)", null, null]);