Files
yara724-api/src/case-expert-report/case-expert-report.controller.ts

62 lines
2.0 KiB
TypeScript

import {
Controller,
Get,
HttpException,
InternalServerErrorException,
Param,
UseGuards,
} from "@nestjs/common";
import {
ApiBearerAuth,
ApiOperation,
ApiParam,
ApiResponse,
ApiTags,
} from "@nestjs/swagger";
import { LocalActorAuthGuard } from "src/auth/guards/actor-local.guard";
import { RolesGuard } from "src/auth/guards/role.guard";
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")
@ApiBearerAuth()
@UseGuards(LocalActorAuthGuard, RolesGuard)
@Roles(RoleEnum.COMPANY)
export class CaseExpertReportInsurerController {
constructor(
private readonly caseExpertReportService: CaseExpertReportService,
) {}
@Get("files/:publicId/report")
@ApiOperation({
summary: "Get insurer file report data",
description:
"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" })
@ApiResponse({ status: 200, description: "Report data" })
@ApiResponse({ status: 404, description: "File not found for this publicId" })
async getInsurerReport(
@CurrentUser() insurer: { clientKey?: string },
@Param("publicId") publicId: string,
): Promise<InsurerFileReportViewModel> {
try {
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 retrieve insurer file report data",
);
}
}
}