import { BadRequestException, Controller, Get, Param, Query, UseGuards, } from "@nestjs/common"; import { ApiBearerAuth, ApiOperation, ApiParam, ApiQuery, ApiTags, } from "@nestjs/swagger"; import { LocalActorAuthGuard } from "src/auth/guards/actor-local.guard"; import { CurrentUser } from "src/decorators/user.decorator"; import { FANAVARAN_CLIENT_SWAGGER_ENUM, isFanavaranClientKey, normalizeFanavaranClientKey, } from "src/core/config/fanavaran-client.config"; import { FanavaranHullReadService } from "./fanavaran-hull-read.service"; @ApiTags("fanavaran") @ApiBearerAuth() @UseGuards(LocalActorAuthGuard) @ApiParam({ name: "client", enum: FANAVARAN_CLIENT_SWAGGER_ENUM }) @ApiParam({ name: "claimCaseId", description: "Local claim case MongoDB ObjectId; the saved Fanavaran claimId is used upstream", }) @Controller("v2/fanavaran/:client/claim-cases/:claimCaseId/hull") export class FanavaranHullReadController { constructor(private readonly hull: FanavaranHullReadService) {} @Get("files") @ApiOperation({ summary: "Retrieve submitted hull attachment metadata from Fanavaran (GEN.05)", description: "Live file list, including Id, ClaimId, FileName, FileTypeId and Status. The list does not include Base64 Data. Does not depend on locally recorded file IDs.", }) files( @Param("client") client: string, @Param("claimCaseId") claimCaseId: string, @CurrentUser() actor: any, ) { return this.hull.files(this.clientKey(client), claimCaseId, actor); } @Get("files/:fileId") @ApiParam({ name: "fileId", type: Number, description: "Fanavaran file Id returned by the remote file list", }) @ApiOperation({ summary: "Retrieve a submitted hull file including Base64 Data (GEN.05)", }) file( @Param("client") client: string, @Param("claimCaseId") claimCaseId: string, @Param("fileId") fileId: string, @CurrentUser() actor: any, ) { return this.hull.file(this.clientKey(client), claimCaseId, fileId, actor); } @Get("expertise/dmg-sections") @ApiQuery({ name: "expertiseId", required: false, type: Number, description: "Optional historical Fanavaran expertise Id; defaults to the saved expertiseId", }) @ApiOperation({ summary: "Retrieve submitted hull expertise damage sections and costs (GEN.12)", description: "Reads live damage section IDs, costs, amounts, CINumber and CITrackingCode when supplied by Fanavaran. Does not resubmit expertise.", }) damageSections( @Param("client") client: string, @Param("claimCaseId") claimCaseId: string, @CurrentUser() actor: any, @Query("expertiseId") expertiseId?: string, ) { return this.hull.damageSections( this.clientKey(client), claimCaseId, actor, expertiseId, ); } private clientKey(client: string) { if (!isFanavaranClientKey(client)) throw new BadRequestException({ statusCode: 400, code: "FANAVARAN_CLIENT_INVALID", field: "client", allowedClients: FANAVARAN_CLIENT_SWAGGER_ENUM, message: "شرکت بیمه انتخاب‌شده برای سرویس فناوران معتبر نیست.", }); return normalizeFanavaranClientKey(client); } }