diff --git a/src/case-expert-report/case-expert-report-pdf.service.ts b/src/case-expert-report/case-expert-report-pdf.service.ts deleted file mode 100644 index ab270ad..0000000 --- a/src/case-expert-report/case-expert-report-pdf.service.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { Injectable } from "@nestjs/common"; -import { - createPersianPdfDocument, - persianPdfToBuffer, -} from "src/helpers/persian-pdf-document"; -import { - InsurerFileReportPdfResult, - InsurerFileReportViewModel, -} from "./case-expert-report.types"; -import { PR } from "./persian-report-labels"; - -@Injectable() -export class CaseExpertReportPdfService { - async render(model: InsurerFileReportViewModel): Promise { - const pdf = createPersianPdfDocument(); - pdf.addTitle(model.title); - pdf.addKeyValue(PR.publicId, model.publicId); - pdf.addKeyValue(PR.requestNo, model.requestNo); - pdf.addBlank(); - - for (const section of model.sections) { - pdf.addSection(section.title); - for (const field of section.fields) { - pdf.addKeyValue(field.label, field.value); - } - pdf.addBlank(); - } - - const buffer = await persianPdfToBuffer(pdf); - const safeId = (model.publicId || "file").replace(/[^\w.-]+/g, "_"); - return { - buffer, - filename: `insurer-file-report-${safeId}.pdf`, - }; - } -} diff --git a/src/case-expert-report/case-expert-report.controller.ts b/src/case-expert-report/case-expert-report.controller.ts index 362a8dd..41f17cd 100644 --- a/src/case-expert-report/case-expert-report.controller.ts +++ b/src/case-expert-report/case-expert-report.controller.ts @@ -4,14 +4,12 @@ import { HttpException, InternalServerErrorException, Param, - StreamableFile, UseGuards, } from "@nestjs/common"; import { ApiBearerAuth, ApiOperation, ApiParam, - ApiProduces, ApiResponse, ApiTags, } from "@nestjs/swagger"; @@ -21,6 +19,7 @@ import { Roles } from "src/decorators/roles.decorator"; import { CurrentUser } from "src/decorators/user.decorator"; import { RoleEnum } from "src/Types&Enums/role.enum"; import { CaseExpertReportService } from "./case-expert-report.service"; +import { InsurerFileReportViewModel } from "./case-expert-report.types"; @ApiTags("expert-insurer-panel") @Controller("expert-insurer") @@ -32,36 +31,30 @@ export class CaseExpertReportInsurerController { private readonly caseExpertReportService: CaseExpertReportService, ) {} - @Get("files/:publicId/report.pdf") + @Get("files/:publicId/report") @ApiOperation({ - summary: "Download insurer file report PDF", + summary: "Get insurer file report data", description: - "Generates a PDF for the shared publicId (blame + claim combined): damaged owner, driver when different, insurance, vehicle, and accident report sections.", + "Returns the structured report data for the given publicId (blame + claim combined): damaged owner, driver when different, insurance, vehicle, and accident report sections. The front-end uses this data to render and generate the PDF.", }) @ApiParam({ name: "publicId" }) - @ApiProduces("application/pdf") - @ApiResponse({ status: 200, description: "PDF file" }) + @ApiResponse({ status: 200, description: "Report data" }) @ApiResponse({ status: 404, description: "File not found for this publicId" }) - async downloadInsurerReport( + async getInsurerReport( @CurrentUser() insurer: { clientKey?: string }, @Param("publicId") publicId: string, - ): Promise { + ): Promise { try { - const { buffer, filename } = - await this.caseExpertReportService.generateForInsurer( - publicId, - insurer, - ); - return new StreamableFile(buffer, { - type: "application/pdf", - disposition: `attachment; filename="${filename}"`, - }); + return await this.caseExpertReportService.generateForInsurer( + publicId, + insurer, + ); } catch (error) { if (error instanceof HttpException) throw error; throw new InternalServerErrorException( error instanceof Error ? error.message - : "Failed to generate insurer file report PDF", + : "Failed to retrieve insurer file report data", ); } } diff --git a/src/case-expert-report/case-expert-report.module.ts b/src/case-expert-report/case-expert-report.module.ts index 5d8c302..85ec3a2 100644 --- a/src/case-expert-report/case-expert-report.module.ts +++ b/src/case-expert-report/case-expert-report.module.ts @@ -1,13 +1,12 @@ import { Module } from "@nestjs/common"; import { ExpertInsurerModule } from "src/expert-insurer/expert-insurer.module"; import { CaseExpertReportInsurerController } from "./case-expert-report.controller"; -import { CaseExpertReportPdfService } from "./case-expert-report-pdf.service"; import { CaseExpertReportService } from "./case-expert-report.service"; @Module({ imports: [ExpertInsurerModule], controllers: [CaseExpertReportInsurerController], - providers: [CaseExpertReportService, CaseExpertReportPdfService], + providers: [CaseExpertReportService], exports: [CaseExpertReportService], }) export class CaseExpertReportModule {} diff --git a/src/case-expert-report/case-expert-report.service.ts b/src/case-expert-report/case-expert-report.service.ts index 8952c81..b278bc1 100644 --- a/src/case-expert-report/case-expert-report.service.ts +++ b/src/case-expert-report/case-expert-report.service.ts @@ -1,20 +1,18 @@ import { Injectable, NotFoundException } from "@nestjs/common"; import { ExpertInsurerService } from "src/expert-insurer/expert-insurer.service"; import { buildInsurerFileReport } from "./case-expert-report.builder"; -import { CaseExpertReportPdfService } from "./case-expert-report-pdf.service"; -import { InsurerFileReportPdfResult } from "./case-expert-report.types"; +import { InsurerFileReportViewModel } from "./case-expert-report.types"; @Injectable() export class CaseExpertReportService { constructor( private readonly expertInsurerService: ExpertInsurerService, - private readonly pdfService: CaseExpertReportPdfService, ) {} async generateForInsurer( publicId: string, actor: { clientKey?: string }, - ): Promise { + ): Promise { const clientKey = actor?.clientKey; if (!clientKey) { throw new NotFoundException("Insurer context not found"); @@ -24,7 +22,6 @@ export class CaseExpertReportService { clientKey, publicId, ); - const model = buildInsurerFileReport(file); - return this.pdfService.render(model); + return buildInsurerFileReport(file); } } diff --git a/src/case-expert-report/case-expert-report.types.ts b/src/case-expert-report/case-expert-report.types.ts index b98cbb1..e292564 100644 --- a/src/case-expert-report/case-expert-report.types.ts +++ b/src/case-expert-report/case-expert-report.types.ts @@ -14,8 +14,3 @@ export type InsurerFileReportViewModel = { requestNo?: string; sections: InsurerFileReportSection[]; }; - -export type InsurerFileReportPdfResult = { - buffer: Buffer; - filename: string; -};