feat(reports): PDF report generator (rebased on main, conflict-free) — supersedes #8#9
Merged
Merged
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.
NischalaV-4
pushed a commit
to NischalaV-4/CLIMATRIX
that referenced
this pull request
May 29, 2026
Original work by Anshika Sharma (PR D-source1602#10) — rebased on top of current main. Original PR was based on an old main (only PR D-source1602#5 merged) and the diff showed a 2300-line 'deletion' of PRs D-source1602#6, D-source1602#7, D-source1602#9 as a side-effect. This commit reconstructs only the additive changes: BACKEND - backend/src/routes/anomaly.routes.ts (new) Pure stats anomaly detector: rolling z-score (window=5) and sudden percentage spike. Stateless POST /api/v1/anomaly/detect endpoint. Severity grading (low/medium/high) by zScore and pct increase. Mounted via the established routes/index.ts pattern (consistent with /auth, /aqi, /reports), not via a parallel app.use in app.ts. FRONTEND - src/lib/anomaly.ts (new) Typed wrapper around the shared api() helper; uses VITE_API_URL. - src/App.tsx Adds RUN SPIKE SCAN button on the AI Anomaly Detection capability card with severity-colored result panel. BUG FIX vs original PR D-source1602#10: - Original frontend hard-coded http://localhost:5000/api/v1/anomaly/detect. Backend runs on :4000 — the feature would have 100% failed in the demo. Switched to api() helper which reads VITE_API_URL. Architecture preserved: the route shape mirrors what a future FastAPI + Isolation Forest microservice would expose, so swapping in real ML later is contained to the detect() function body.
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
This is the conflict-free version of PR #8 (PDF report generator), rebased on top of
mainafter PR #7 (realtime AQI) was merged. Same content as PR #8, just with the conflicts inbackend/package.json,backend/prisma/schema.prisma, andbackend/src/routes/index.tsresolved.Action needed: merge this PR, then close PR #8 (it's now superseded).
Why this exists
PRs #7 and #8 were developed in parallel. After PR #7 merged, PR #8 had merge conflicts because both PRs touched:
backend/package.json— both add deps (resolved: keep all ofnode-cron,socket.io,pdfkit, plus types)backend/prisma/schema.prisma— both append a new model at the bottom (resolved: keep bothAirQualityReadingandReportmodels)backend/src/routes/index.ts— both add a router import + mount (resolved: keep bothaqiRouterandreportRouter)src/App.tsxauto-merged cleanly because PR #7 addedLiveAirQualityPanelwhile PR #8 modified theReportscomponent — different sections of the same file.Conflict resolutions
backend/package.json(both sides kept)backend/src/routes/index.ts(both sides kept)backend/prisma/schema.prisma(both models kept)The
AirQualityReadingmodel from PR #7 and theReportmodel +ReportType/ReportFormatenums from PR #8 are now stacked at the bottom of the schema, in that order.What this PR ships (unchanged from PR #8)
PDF report generator wired end-to-end:
pdfkit-based generator (~2 MB, no Chromium) with brand-matching layout, KPI grid, color-coded status tableReportPrisma model +ReportType/ReportFormatenums + back-relations onUserandIndustryPOST /reports/generate,GET /reports,GET /reports/:id/download,DELETE /reports/:id— all auth-protected viarequireAuthbackend/files/reports/<uuid>.pdf(gitignored)air_quality_readingstableTo run after merging
Open
http://localhost:5173, log in, click Reports → GENERATE REPORT → DOWNLOAD. PDF lands in your Downloads folder.Diff stat
Same as PR #8: 9 files, +1065 / -21.