refactor: Link ownership-costs to documents feature (#29) #30

Merged
egullickson merged 5 commits from issue-29-link-ownership-costs into main 2026-01-15 01:23:57 +00:00
Owner

Summary

  • Create ownership_costs backend feature capsule with CRUD API
  • Integrate DocumentsService to auto-create costs when insurance/registration documents have cost data
  • Add frontend OwnershipCostForm and OwnershipCostsList components
  • Leverage existing TCO endpoint and TCODisplay (already implemented)

Key Changes

Backend:

  • New ownership_costs table with 6 cost types and optional document_id FK
  • Auto-create ownership_cost when document has premium/cost in details
  • Sync cost changes on document update
  • CASCADE delete when document is deleted

Frontend:

  • OwnershipCostForm with vehicle selector, cost type, amount, dates
  • OwnershipCostsList for viewing/editing costs
  • Mobile-friendly (44px touch targets), dark mode support

Test Plan

  • Create insurance document with premium - verify ownership_cost auto-created
  • Create registration document with cost - verify ownership_cost auto-created
  • Update document cost - verify linked ownership_cost updated
  • Delete document - verify linked ownership_cost deleted (CASCADE)
  • View TCO on vehicle detail - verify ownership costs included
  • Test OwnershipCostForm on mobile (320px) and desktop (1920px)

Fixes #29

🤖 Generated with Claude Code

## Summary - Create `ownership_costs` backend feature capsule with CRUD API - Integrate DocumentsService to auto-create costs when insurance/registration documents have cost data - Add frontend OwnershipCostForm and OwnershipCostsList components - Leverage existing TCO endpoint and TCODisplay (already implemented) ## Key Changes **Backend:** - New `ownership_costs` table with 6 cost types and optional `document_id` FK - Auto-create ownership_cost when document has premium/cost in details - Sync cost changes on document update - CASCADE delete when document is deleted **Frontend:** - OwnershipCostForm with vehicle selector, cost type, amount, dates - OwnershipCostsList for viewing/editing costs - Mobile-friendly (44px touch targets), dark mode support ## Test Plan - [ ] Create insurance document with premium - verify ownership_cost auto-created - [ ] Create registration document with cost - verify ownership_cost auto-created - [ ] Update document cost - verify linked ownership_cost updated - [ ] Delete document - verify linked ownership_cost deleted (CASCADE) - [ ] View TCO on vehicle detail - verify ownership costs included - [ ] Test OwnershipCostForm on mobile (320px) and desktop (1920px) Fixes #29 🤖 Generated with [Claude Code](https://claude.com/claude-code)
egullickson added 4 commits 2026-01-14 03:38:10 +00:00
Milestone 1: Complete backend feature with:
- Migration with CHECK (amount > 0) constraint
- Repository with mapRow() for snake_case -> camelCase
- Service with CRUD and vehicle authorization
- Controller with HTTP handlers
- Routes registered at /api/ownership-costs
- Validation with Zod schemas
- README with endpoint documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Milestone 2: Auto-create ownership_cost when insurance/registration
document is created with cost data (premium or cost field).

- Add OwnershipCostsService integration
- Auto-create cost on document create when amount > 0
- Sync cost changes on document update
- mapDocumentTypeToCostType() validation
- extractCostAmount() for premium/cost field extraction
- CASCADE delete handled by FK constraint

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Milestone 4: Complete frontend with:
- Types aligned with backend schema
- API client for CRUD operations
- React Query hooks with optimistic updates
- OwnershipCostForm with all 6 cost types
- OwnershipCostsList with edit/delete actions
- Mobile-friendly (44px touch targets)
- Full dark mode support

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
fix: resolve lint error in ownership-costs types (refs #29)
All checks were successful
Deploy to Staging / Build Images (pull_request) Successful in 4m37s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 37s
Deploy to Staging / Verify Staging (pull_request) Successful in 7s
Deploy to Staging / Notify Staging Ready (pull_request) Successful in 6s
Deploy to Staging / Notify Staging Failure (pull_request) Has been skipped
1d95eba395
Milestone 6: Change empty interface to type alias to fix
@typescript-eslint/no-empty-object-type error

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
egullickson added 1 commit 2026-01-14 03:51:54 +00:00
fix: add schema migration for ownership_costs table (refs #29)
All checks were successful
Deploy to Staging / Build Images (pull_request) Successful in 2m21s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 28s
Deploy to Staging / Verify Staging (pull_request) Successful in 7s
Deploy to Staging / Notify Staging Ready (pull_request) Successful in 6s
Deploy to Staging / Notify Staging Failure (pull_request) Has been skipped
025ab30726
The ownership_costs table was created with an outdated schema that had
different column names (start_date/end_date vs period_start/period_end)
and was missing the notes column. This migration aligns the database
schema with the current code expectations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
egullickson merged commit a5d828b6c1 into main 2026-01-15 01:23:57 +00:00
egullickson deleted branch issue-29-link-ownership-costs 2026-01-15 01:23:57 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: egullickson/motovaultpro#30