feat(projects): task create, update and delete (app#2048)

Merged
SW
3mo ago
+593-0

Implements the task-CRUD api row of recoupable/app#2048. Contract: recoupable/docs#326.

Stacked on #881 and includes its commits until that merges — this branch is built on it because every endpoint here goes through the same requireProjectAccess guard. Review #881 first; the diff here shrinks to just these files once it lands.

Also blocked on recoupable/database#68 for the same reason as #881: the tables are not in types/database.types.ts yet, so tsc fails. Merge that, run pnpm update-types, and I will push the regenerated types.

What this adds

EndpointPurpose
POST /api/projects/{projectId}/tasksCreate a task
PATCH /api/projects/{projectId}/tasks/{taskId}Update a task, including the completion toggle
DELETE /api/projects/{projectId}/tasks/{taskId}Delete a task and, by cascade, its comments

This is what makes a project seedable. There is no project-creation endpoint by design, so tasks are authored over the API from Claude Code rather than through a UI.

The decisions worth reviewing

Completion is the server's word, not the client's. toTaskUpdates stamps completed_at from the server clock and completed_by from the authenticated account. The validator does not accept either field, and there is a test asserting that a caller sending completed_at: "1999-01-01" has it dropped. Any collaborator may close or reopen any task, the client included — the row records which one did.

An empty PATCH body is a 400. A no-op 200 for a body that changes nothing hides a broken client. The Zod schema .refines on at least one key.

null and absent are different. toTaskUpdates maps an explicit due_date: null through to clear the column, while omitting the field leaves it alone. Tested, because collapsing the two would make a due date unclearable.

Both ids are matched on every write. updateProjectTask and deleteProjectTask filter on project_id and id, so a task belonging to another project cannot be written through a project the caller does collaborate on.

Verification

  • vitest lib/projects: 12 tests, passing. validateUpdateProjectTaskBody and toTaskUpdates were written test-first.
  • eslint: clean.
  • tsc: fails only on the missing table types described above.
  • Not preview-verified yet — the tables do not exist. Live checks, including deliberate 400s (empty body, malformed due_date, non-UUID assignee) and a 404 for a non-collaborator, go in a comment before this merges.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BTaK5sDuryYsQG5W56mR5n


Summary by cubic

Adds task create, update, and delete endpoints for projects, which makes a project seedable over the API. All new routes sit behind the requireProjectAccess guard, which returns 404 rather than 403 so real project ids aren't confirmed to callers.

Behavior

  • Completion toggles through PATCH's completed boolean; the server stamps completed_at and completed_by, and the validator never accepts either field from the caller.
  • An empty PATCH body returns 400 instead of a no-op 200.
  • An explicit due_date: null clears the column; omitting due_date leaves it as-is.
  • Writes match both project_id and task id, so a task from another project can't be written through a project the caller collaborates on.
  • Malformed project or task ids return 400; PATCH and DELETE previously returned 500 and POST returned 404 by accident.