feat: Backend migration and API updates for maintenance receipt linking (#16) #151
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Relates to #16
Summary
Add database migration for
receipt_document_idFK on maintenance_records, update backend types/repository/service/controller to support receipt document linking, and add OCR proxy endpoint in theocrfeature.Scope
receipt_document_id(nullable UUID FK to documents) onmaintenance_recordsMaintenanceRecordtype to includereceiptDocumentIdmapRow()for new field, update create/get queriesreceiptDocumentIdon createreceiptDocumentIdthrough, return receipt document metadata on GETPOST /api/ocr/extract/maintenance-receipt(proxies to OCR microservice)requireTier('maintenance.receiptScan')preHandlerFiles
backend/src/features/maintenance/migrations/004_add_receipt_document_id.sql(NEW)backend/src/features/maintenance/domain/maintenance.types.ts(MODIFY)backend/src/features/maintenance/data/maintenance.repository.ts(MODIFY)backend/src/features/maintenance/domain/maintenance.service.ts(MODIFY)backend/src/features/maintenance/api/maintenance.controller.ts(MODIFY)backend/src/features/ocr/api/ocr.routes.ts(MODIFY - add route with requireTier preHandler)backend/src/features/ocr/api/ocr.controller.ts(MODIFY - add extractMaintenanceReceipt handler)backend/src/features/ocr/domain/ocr.service.ts(MODIFY - add extractMaintenanceReceipt method)backend/src/features/ocr/domain/ocr.types.ts(MODIFY - add maintenance receipt response types)backend/src/features/ocr/external/ocr-client.ts(MODIFY - add extractMaintenanceReceipt HTTP call)backend/src/core/config/feature-tiers.ts(MODIFY - add maintenance.receiptScan feature key)Technical Notes
ALTER TABLE maintenance_records ADD COLUMN receipt_document_id UUID REFERENCES documents(id) ON DELETE SET NULL;preHandler: [requireAuth, requireTier('maintenance.receiptScan')](follows existingocr.routes.tsline 29 pattern)receiptDocumentIdZod UUID fieldAcceptance Criteria
receipt_document_idnullable FK to maintenance_recordsreceiptDocumentIdrequireTier('maintenance.receiptScan')preHandlerMilestone: Execution Complete
Phase: Execution | Agent: Developer | Status: PASS
Changes (10 files, +285/-7)
Migration & Types (Milestone 1)
migrations/004_add_receipt_document_id.sql- NEW:receipt_document_id UUID REFERENCES documents(id) ON DELETE SET NULLwith partial indexmaintenance.types.ts- AddedreceiptDocumentIdtoMaintenanceRecord,ReceiptDocumentMetainterface,receiptDocumenton response, optionalreceiptDocumentIdinCreateMaintenanceRecordSchemafeature-tiers.ts- Addedmaintenance.receiptScanfeature key (Pro tier)Repository & Service (Milestones 2-3)
maintenance.repository.ts- UpdatedmapRow,insertRecordforreceipt_document_id, addedfindRecordByIdWithDocumentwith LEFT JOIN to documents tablemaintenance.service.ts-createRecordpassesreceiptDocumentId,getRecordreturns receipt document metadata viafindRecordByIdWithDocumentOCR Proxy Endpoint (Milestone 4)
ocr.types.ts- AddedMaintenanceReceiptExtractRequesttypeocr-client.ts- AddedextractMaintenanceReceipt()HTTP call tomvp-ocr:8000/extract/maintenance-receiptocr.service.ts- AddedextractMaintenanceReceipt()with image-only validation and size limitsocr.controller.ts- AddedextractMaintenanceReceipt()handler with file upload, MIME validation, error handlingocr.routes.ts- AddedPOST /ocr/extract/maintenance-receiptwithrequireTier('maintenance.receiptScan')preHandlerQuality
npx tsc --noEmitclean)anywarnings, no new issues)Acceptance Criteria
receipt_document_idnullable FK to maintenance_recordsreceiptDocumentIdrequireTier('maintenance.receiptScan')preHandlerVerdict: PASS | Next: Push and open PR when parent issue #16 is ready