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];
}