From 57a206d7b331b5b49a6a16331901766031cb8378 Mon Sep 17 00:00:00 2001 From: Michael Freno Date: Sat, 9 May 2026 22:57:03 -0400 Subject: [PATCH] Fix type errors in report routes (redundant parseInt, JsonValue cast) (FRE-4575) Co-Authored-By: Paperclip --- packages/api/src/routes/report.routes.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/api/src/routes/report.routes.ts b/packages/api/src/routes/report.routes.ts index 2c7e3b0..a8b0b84 100644 --- a/packages/api/src/routes/report.routes.ts +++ b/packages/api/src/routes/report.routes.ts @@ -1,7 +1,7 @@ import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify'; import { reportService } from '@shieldai/report'; import { prisma } from '@shieldai/db'; -import { ReportType, ReportStatus } from '@shieldai/types'; +import { ReportType, ReportStatus, ReportDataPayload } from '@shieldai/types'; interface AuthRequest extends FastifyRequest { user?: { @@ -63,7 +63,7 @@ export async function reportRoutes(fastify: FastifyInstance) { const limit = parseInt(query.limit || '20', 10); const offset = parseInt(query.offset || '0', 10); - const reports = await reportService.getReportHistory(userId, parseInt(limit), parseInt(offset)); + const reports = await reportService.getReportHistory(userId, limit, offset); return reply.code(200).send({ reports, count: reports.length }); }); @@ -136,18 +136,21 @@ export async function reportRoutes(fastify: FastifyInstance) { } const { pdfGenerator } = await import('@shieldai/report'); - const pdfBuffer = await pdfGenerator.generate({ - reportTitle: report.title, - periodStart: '', - periodEnd: '', - generatedAt: new Date().toISOString(), - data: report.dataPayload ? JSON.parse(report.dataPayload) : { + const pdfData = report.dataPayload + ? (typeof report.dataPayload === 'string' ? JSON.parse(report.dataPayload) : report.dataPayload as unknown as ReportDataPayload) + : { exposureSummary: { totalExposures: 0, newExposures: 0, resolvedExposures: 0, criticalExposures: 0, warningExposures: 0, infoExposures: 0, exposuresBySource: {} }, spamStats: { callsBlocked: 0, textsBlocked: 0, callsFlagged: 0, textsFlagged: 0, falsePositives: 0, totalSpamEvents: 0 }, voiceStats: { analysesRun: 0, threatsDetected: 0, enrollmentsActive: 0, syntheticDetections: 0, voiceMismatchEvents: 0 }, recommendations: [], protectionScore: 0, - }, + }; + const pdfBuffer = await pdfGenerator.generate({ + reportTitle: report.title, + periodStart: '', + periodEnd: '', + generatedAt: new Date().toISOString(), + data: pdfData, reportId, });