Files
motovaultpro/backend/src/features/ocr/api/ocr.routes.ts
Eric Gullickson 88d23d2745 feat: add backend migration and API for maintenance receipt linking (refs #151)
Add receipt_document_id FK on maintenance_records, update types/repo/service
to support receipt linking on create and return document metadata on GET.
Add OCR proxy endpoint POST /api/ocr/extract/maintenance-receipt with
tier gating (maintenance.receiptScan) through full chain: routes -> controller
-> service -> client.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 21:24:24 -06:00

57 lines
1.9 KiB
TypeScript

/**
* @ai-summary Fastify routes for OCR API
*/
import { FastifyInstance, FastifyPluginAsync, FastifyPluginOptions } from 'fastify';
import { requireTier } from '../../../core/middleware/require-tier';
import { OcrController } from './ocr.controller';
export const ocrRoutes: FastifyPluginAsync = async (
fastify: FastifyInstance,
_opts: FastifyPluginOptions
) => {
const ctrl = new OcrController();
const requireAuth = fastify.authenticate.bind(fastify);
// POST /api/ocr/extract - Synchronous OCR extraction
fastify.post('/ocr/extract', {
preHandler: [requireAuth],
handler: ctrl.extract.bind(ctrl),
});
// POST /api/ocr/extract/vin - VIN-specific OCR extraction
fastify.post('/ocr/extract/vin', {
preHandler: [requireAuth],
handler: ctrl.extractVin.bind(ctrl),
});
// POST /api/ocr/extract/receipt - Receipt-specific OCR extraction (Pro tier required)
fastify.post('/ocr/extract/receipt', {
preHandler: [requireAuth, requireTier('fuelLog.receiptScan')],
handler: ctrl.extractReceipt.bind(ctrl),
});
// POST /api/ocr/extract/maintenance-receipt - Maintenance receipt OCR extraction (Pro tier required)
fastify.post('/ocr/extract/maintenance-receipt', {
preHandler: [requireAuth, requireTier('maintenance.receiptScan')],
handler: ctrl.extractMaintenanceReceipt.bind(ctrl),
});
// POST /api/ocr/extract/manual - Manual extraction (Pro tier required)
fastify.post('/ocr/extract/manual', {
preHandler: [requireAuth, fastify.requireTier({ featureKey: 'document.scanMaintenanceSchedule' })],
handler: ctrl.extractManual.bind(ctrl),
});
// POST /api/ocr/jobs - Submit async OCR job
fastify.post('/ocr/jobs', {
preHandler: [requireAuth],
handler: ctrl.submitJob.bind(ctrl),
});
// GET /api/ocr/jobs/:jobId - Get job status
fastify.get<{ Params: { jobId: string } }>('/ocr/jobs/:jobId', {
preHandler: [requireAuth],
handler: ctrl.getJobStatus.bind(ctrl),
});
};