forked from Yara724/api
fanavaran added 2 apis for get payload and submit manually
This commit is contained in:
124
src/fanavaran/fanavaran.controller.ts
Normal file
124
src/fanavaran/fanavaran.controller.ts
Normal file
@@ -0,0 +1,124 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Query,
|
||||
UseGuards,
|
||||
} from "@nestjs/common";
|
||||
import {
|
||||
ApiBearerAuth,
|
||||
ApiOperation,
|
||||
ApiParam,
|
||||
ApiQuery,
|
||||
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 { RoleEnum } from "src/Types&Enums/role.enum";
|
||||
import { ClaimRequestManagementService } from "src/claim-request-management/claim-request-management.service";
|
||||
import {
|
||||
isFanavaranClientKey,
|
||||
listFanavaranClientProfiles,
|
||||
normalizeFanavaranClientKey,
|
||||
resolveFanavaranClientKey,
|
||||
} from "src/core/config/fanavaran-client.config";
|
||||
|
||||
@ApiTags("fanavaran")
|
||||
@Controller("v2/fanavaran")
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(LocalActorAuthGuard, RolesGuard)
|
||||
@Roles(RoleEnum.ADMIN, RoleEnum.FIELD_EXPERT)
|
||||
export class FanavaranController {
|
||||
constructor(
|
||||
private readonly claimRequestManagementService: ClaimRequestManagementService,
|
||||
) {}
|
||||
|
||||
@Get("clients")
|
||||
@ApiOperation({
|
||||
summary: "List supported Fanavaran insurance clients",
|
||||
description:
|
||||
"Returns configured Fanavaran tenants (parsian, tejaratno) and which client is active for this deployment.",
|
||||
})
|
||||
listClients() {
|
||||
const activeClient = resolveFanavaranClientKey();
|
||||
return {
|
||||
activeClient,
|
||||
clients: listFanavaranClientProfiles().map((profile) => ({
|
||||
key: profile.key,
|
||||
defaults: profile.defaults,
|
||||
isActive: profile.key === activeClient,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
@Get(":client/claim-cases/:claimCaseId")
|
||||
@ApiOperation({
|
||||
summary: "Preview Fanavaran submit payload (V2)",
|
||||
description:
|
||||
"Builds the third-party-car-financial-claims body from claimCases + blameCases without calling Fanavaran.",
|
||||
})
|
||||
@ApiParam({
|
||||
name: "client",
|
||||
description: "Fanavaran tenant key",
|
||||
enum: ["parsian", "tejaratno"],
|
||||
})
|
||||
@ApiParam({
|
||||
name: "claimCaseId",
|
||||
description: "Claim case MongoDB ObjectId",
|
||||
})
|
||||
@ApiQuery({
|
||||
name: "debug",
|
||||
required: false,
|
||||
description: "When true, returns payload plus mapping debug steps",
|
||||
})
|
||||
async preview(
|
||||
@Param("client") client: string,
|
||||
@Param("claimCaseId") claimCaseId: string,
|
||||
@Query("debug") debug?: string,
|
||||
) {
|
||||
const clientKey = this.parseClientParam(client);
|
||||
return await this.claimRequestManagementService.previewFanavaranSubmitV2(
|
||||
claimCaseId,
|
||||
clientKey,
|
||||
{ debug: debug === "1" || debug === "true" },
|
||||
);
|
||||
}
|
||||
|
||||
@Post(":client/claim-cases/:claimCaseId")
|
||||
@ApiOperation({
|
||||
summary: "Submit claim to Fanavaran (V2)",
|
||||
description:
|
||||
"Authenticates with the selected client credentials and submits the mapped claimCases + blameCases payload.",
|
||||
})
|
||||
@ApiParam({
|
||||
name: "client",
|
||||
description: "Fanavaran tenant key",
|
||||
enum: ["parsian", "tejaratno"],
|
||||
})
|
||||
@ApiParam({
|
||||
name: "claimCaseId",
|
||||
description: "Claim case MongoDB ObjectId",
|
||||
})
|
||||
async submit(
|
||||
@Param("client") client: string,
|
||||
@Param("claimCaseId") claimCaseId: string,
|
||||
) {
|
||||
const clientKey = this.parseClientParam(client);
|
||||
return await this.claimRequestManagementService.submitFanavaranV2(
|
||||
claimCaseId,
|
||||
clientKey,
|
||||
);
|
||||
}
|
||||
|
||||
private parseClientParam(client: string) {
|
||||
if (!isFanavaranClientKey(client)) {
|
||||
throw new BadRequestException(
|
||||
`Invalid Fanavaran client "${client}". Expected one of: parsian, tejaratno`,
|
||||
);
|
||||
}
|
||||
return normalizeFanavaranClientKey(client);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user