Skip to content

feat: reference categories from tasks by ID - #35

Merged
TechnicPotato merged 2 commits into
mainfrom
task-category-id
Dec 1, 2026
Merged

TechnicPotato merged 2 commits into
mainfrom
task-category-id

Conversation

@TechnicPotato

@TechnicPotato TechnicPotato commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

Tasks now point at a category entity by categoryId instead of storing a free-text category name (ADR 0001). Renaming a category becomes a single write, and every task shows the new name.

  • categoryId: string | null, where null means Uncategorised. It's a UI label, not a stored category.
  • The schema accepts a non-empty ID or null, and defaults to null when omitted.

Changes

Area Change
Task model and schema category: string → categoryId: string | null. The old trim and length rules are removed, since an ID isn't typed by a person.
Task stores The in-memory and Firestore stores save categoryId as given. The stores stay independent of each other: checking that the category exists is the API route's job.
POST /api/tasks If categoryId isn't null, the route checks that the category exists. An unknown ID → 400 Category not found. (the request body refers to something invalid; the endpoint itself exists).
Task list Loads tasks and categories in parallel and looks up each task's category name in a map. A null ID, or one with no matching category, shows Uncategorised.
Add-task form The free-text category input is removed, so new tasks are Uncategorised until the category picker arrives (step 6).

Data: reset, not migrated

Existing Firestore task documents store category and have no categoryId. They would fail validation on read. Production only holds test data, so I'll delete the tasks collection straight after merging rather than write a migration.

Known gap

The route checks the category, then creates the task, in two separate steps. A category deleted in between would leave a task pointing at nothing. The list handles this safely by showing Uncategorised. Step 8 closes the gap with a transaction when category delete moves tasks to Uncategorised.

Testing

  • Contract tests store and read back a non-null categoryId, so a store that dropped the field would fail.
  • Route tests cover:
    • a real category → 201;
    • categoryId left out → null;
    • an empty ID → 400;
    • an unknown ID → 400 with no task created.
  • Locally, 113/113 tests pass with the Firestore emulator, and typecheck, lint and format check are clean.
  • Checked manually against the emulator: tasks show their category name, or Uncategorised.

Not in this PR

  • The category picker and category management UI.
  • Grouping and filtering by category.
  • Deleting a category moving its tasks to Uncategorised.

@TechnicPotato TechnicPotato changed the title Task category feat: reference categories from tasks by ID Dec 1, 2026
@TechnicPotato
TechnicPotato merged commit 16a3bdd into main Dec 1, 2026
4 checks passed
@TechnicPotato
TechnicPotato deleted the task-category-id branch December 1, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant