feat(reports): PDF report generator (auth-gated download, pdfkit, real schema)#8
Open
kiro-agent[bot] wants to merge 1 commit into
Open
feat(reports): PDF report generator (auth-gated download, pdfkit, real schema)#8kiro-agent[bot] wants to merge 1 commit into
kiro-agent[bot] wants to merge 1 commit into
Conversation
…nloadable) BACKEND - New Report model + ReportType / ReportFormat enums; back-relations on User and Industry. Indexed on (createdAt DESC), (industryId, createdAt DESC). - services/reportService.ts: pdfkit-based generation, ~2 MB dependency (vs Puppeteer's ~300 MB). Brand palette + dashed separators match the frontend's sketch-on-paper aesthetic. KPI grid + striped data tables with status color-coding (green/amber/red). Auto-paginates long lists. - AQI section is gated behind a runtime model probe — this PR is independent of PR #7. Once #7 is merged, reports auto-include an AQI summary; otherwise the section is silently skipped. - POST /api/v1/reports/generate create + persist report + write PDF - GET /api/v1/reports list (scoped: INDUSTRY -> own only) - GET /api/v1/reports/:id/download stream PDF with auth + ownership - DELETE /api/v1/reports/:id remove DB row + best-effort file - All routes auth-protected via requireAuth middleware (PR #5). - Files stored under backend/files/reports/<uuid>.pdf, .gitignored. - New deps: pdfkit, @types/pdfkit. FRONTEND - src/lib/reports.ts: typed list / generate / delete / download helpers, uiTypeToBackend mapper for the existing UI label strings, formatBytes. - App.tsx Reports component: -> Loads real reports from /api/v1/reports on mount (with loading state) -> 'GENERATE REPORT' button now hits backend; period selector mapped to ISO date range (Current Month, Last Month, Q1/Q2 2024, Full Year) -> Report cards show real metadata (title, generatedAt, sizeBytes, pageCount, industry) -> 'DOWNLOAD' button per row uses authenticated fetch + Blob trigger (browsers can't send Authorization on plain anchor downloads) -> Inline error band for both load and generate failures -> Removed the localStorage S.get/S.set scaffolding for reports Migration required after pulling: cd backend && npm install npx prisma migrate dev --name add_reports Independent of PR #7 (realtime AQI). Either merge order works. AQI section of the PDF appears once both this PR and #7 are merged.
D-source1602
added a commit
that referenced
this pull request
May 29, 2026
…ased feat(reports): PDF report generator (rebased on main, conflict-free) — supersedes #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request was created by @kiro-agent on behalf of @D-source1602 👻
Comment with /kiro fix to address specific feedback or /kiro all to address everything.
Learn about Kiro autonomous agent
Summary
Real PDF report generator wired end-to-end. Replaces the mock
setTimeout"GENERATE REPORT" button with a backend-backed PDF that you can actually download.What it does
GENERATE REPORTon the Reports pagepdfkit, persists aReportrow, returns metadataDOWNLOADon a report cardbackend/files/reports/<uuid>.pdfDELon a report card/api/v1/reports(scoped: INDUSTRY users see only their own)Architecture
The PDF layout has a brand bar, dashed separator, KPI grid (records / totals / status counts color-coded green/amber/red), an emissions table, an AQI section (auto-skipped if PR #7 isn't merged), and a footer strapline. Built-in Helvetica only — no font shipping.
Why pdfkit over Puppeteer
Endpoints (all behind
requireAuth)/api/v1/reports/generate/api/v1/reports/api/v1/reports/:id/download/api/v1/reports/:idSchema additions
Independence from PR #7 (realtime AQI)
Either merge order works. The AQI section of the PDF appears only once both PR #7 and this PR are merged —
reportService.tsdoes a runtime probe onprisma.airQualityReadingand silently skips the section if the model isn't generated. No code-level dependency between the two branches.To run after merging
Open
http://localhost:5173, log in, navigate to the Reports tab. Pick a Report Type + Period, clickGENERATE REPORT. The new card appears in the archive list — clickDOWNLOADand the PDF should land in your Downloads folder.If
backend/files/doesn't exist yet, the service creates it on first import.Diff stat
9 files, +1065 / -21.