feat: Slice 2 (Module 02) — document delete with atomic cascade#16
Conversation
Covers: 204 happy path, atomic cascade with shares, disk-failure 500 path, ownership 403, 404 for unknown id, auth/role guards. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…, Slice 2) - Add findDocumentById and deleteDocumentWithSharesById to the document repository; the latter wraps share + document deletion in a single Drizzle transaction so no observable intermediate state exists. - Add deleteDocument use case: loads the row, checks ownership (403), commits the txn, then attempts to unlink the file. Disk-side failure after a successful txn surfaces as a typed disk_delete_failed result. - Wire DELETE /documents/:id behind requireAuth + requireRole(['patient']) with inline middleware (root /documents middleware doesn't cover sub-paths). Returns 204 on success, 404 DOCUMENT_NOT_FOUND, 403 FORBIDDEN, 500 DELETE_FAILED with the contractually-required body. - Fill in the ts-rest contract entry for delete in packages/contracts. - Add useDeleteDocument mutation hook and a delete button on DocumentList; wire it into the patient documents page with a per-row "Deleting..." state and a delete-error banner. Closes #10. All 75 tests pass; pnpm verify clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Claude finished @mGasiorek998's task in 2m 16s —— View job Review — Slice 2 (Module 02): document delete with atomic cascade
Verdict: ✅ APPROVESolid slice. Use-case logic is small and correct, the DB removal is genuinely atomic via Drizzle's Spec compliance (issue #10)
Architecture
Security
Test quality
Vertical sliceSchema (from Slice 1) → use-case (new) → router (new) → contract (new) → UI hook + button (new) → integration tests (new). End-to-end value delivered. ✅ Suggestions (non-blocking)
|
Summary
DELETE /documents/:idfor the owning patient: 204 + DB row gone + shares gone + file unlinkedDELETE_FAILEDwith the contractually-required body; the committed txn remains the source of truthuseDeleteDocumentmutation hook + delete button on the patient documents listCloses #10
Test plan
pnpm test— 75/75 pass (7 new integration tests for delete: 204 happy path, cascade with shares, 500 disk-fail, 403 ownership, 404 unknown, 401, doctor 403)pnpm typecheckcleanpnpm lintclean🤖 Generated with Claude Code