diff --git a/docs/external-api-curls.md b/docs/external-api-curls.md index c8f038b..7141ed7 100644 --- a/docs/external-api-curls.md +++ b/docs/external-api-curls.md @@ -274,6 +274,20 @@ curl -X GET "$FANAVARAN_BIME_URL/car/code-list/accident-culprit-type" \ -H "ContractId: $CONTRACT_ID" \ -H "Location: $LOCATION" \ -H "Content-Type: application/json" + +curl -X GET "$FANAVARAN_BIME_URL/car/base-info/vehicle-kinds" \ + -H "authenticationToken: $AUTHENTICATION_TOKEN" \ + -H "CorpId: $CORP_ID" \ + -H "ContractId: $CONTRACT_ID" \ + -H "Location: $LOCATION" \ + -H "Content-Type: application/json" + +curl -X GET "$FANAVARAN_BIME_URL/car/vehicles/inquiry-by-vin?vin=IRNKAEK4150012345" \ + -H "authenticationToken: $AUTHENTICATION_TOKEN" \ + -H "CorpId: $CORP_ID" \ + -H "ContractId: $CONTRACT_ID" \ + -H "Location: $LOCATION" \ + -H "Content-Type: application/json" ``` ### 3B. Policy Inquiry By National Code diff --git a/src/fanavaran/fanavaran-lookup.config.ts b/src/fanavaran/fanavaran-lookup.config.ts index 2058bd6..b4dec48 100644 --- a/src/fanavaran/fanavaran-lookup.config.ts +++ b/src/fanavaran/fanavaran-lookup.config.ts @@ -86,6 +86,27 @@ export const FANAVARAN_REMOTE_LOOKUPS: FanavaranRemoteLookupDefinition[] = [ url: `${FANAVARAN_LOOKUP_BASE_URL}/common/base-info/file-types`, cacheFile: "file-types.json", }, + // NEW LOOKUPS ADDED + { + name: "cities", + url: `${FANAVARAN_LOOKUP_BASE_URL}/common/base-info/cities`, + cacheFile: "cities.json", + }, + { + name: "dmg-case-type", + url: `${FANAVARAN_LOOKUP_BASE_URL}/car/code-list/dmg-case-type`, + cacheFile: "dmg-case-type.json", + }, + { + name: "dmg-history-status", + url: `${FANAVARAN_LOOKUP_BASE_URL}/car/code-list/dmg-case-history-status`, + cacheFile: "dmg-history-status.json", + }, + { + name: "provinces", + url: `${FANAVARAN_LOOKUP_BASE_URL}/common/base-info/Provinces`, + cacheFile: "provinces.json", + }, ]; export const TEJARAT_STATIC_ACCIDENT_FILES = { diff --git a/src/fanavaran/fanavaran-lookup.service.ts b/src/fanavaran/fanavaran-lookup.service.ts index 7339361..b4d0588 100644 --- a/src/fanavaran/fanavaran-lookup.service.ts +++ b/src/fanavaran/fanavaran-lookup.service.ts @@ -265,6 +265,23 @@ export class FanavaranLookupService { return this.fetchFromFanavaran(clientKey, url); } + async vehicleById( + clientKey: FanavaranClientKey, + vehicleId: number, + versionNo: number = 1, + ): Promise { + const url = `${FANAVARAN_LOOKUP_BASE_URL}/car/vehicles/${vehicleId}?versionno=${versionNo}`; + return this.fetchFromFanavaran(clientKey, url); + } + + async customerById( + clientKey: FanavaranClientKey, + customerId: number, + ): Promise { + const url = `${FANAVARAN_LOOKUP_BASE_URL}/common/customers/${customerId}`; + return this.fetchFromFanavaran(clientKey, url); + } + async inquiryByUniqueIdentifier( clientKey: FanavaranClientKey, params: { diff --git a/src/lookups/lookups.controller.ts b/src/lookups/lookups.controller.ts index 9a22fc6..dd49c6d 100644 --- a/src/lookups/lookups.controller.ts +++ b/src/lookups/lookups.controller.ts @@ -238,6 +238,59 @@ export class LookupsController { return await this.lookupsService.getFileTypes(); } + @Get("cities") + @ApiOperation({ + summary: "Fanavaran cities lookup", + description: "Returns city codes from common/base-info/cities.", + }) + @ApiOkResponse({ + description: "Returns Fanavaran cities lookup data", + schema: { type: "array", items: { type: "object" } }, + }) + async cities() { + return await this.lookupsService.getCities(); + } + + @Get("provinces") + @ApiOperation({ + summary: "Fanavaran provinces lookup", + description: "Returns province codes from common/base-info/provinces.", + }) + @ApiOkResponse({ + description: "Returns Fanavaran provinces lookup data", + schema: { type: "array", items: { type: "object" } }, + }) + async provinces() { + return await this.lookupsService.getProvinces(); + } + + @Get("dmg-case-type") + @ApiOperation({ + summary: "Fanavaran damage case type lookup", + description: "Returns damage case type codes from car/code-list/dmg-case-type.", + }) + @ApiOkResponse({ + description: "Returns Fanavaran damage case type lookup data", + schema: { type: "array", items: { type: "object" } }, + }) + async dmgCaseType() { + return await this.lookupsService.getDmgCaseType(); + } + + @Get("dmg-history-status") + @ApiOperation({ + summary: "Fanavaran damage history status lookup", + description: + "Returns damage history status codes from car/code-list/dmg-case-history-status.", + }) + @ApiOkResponse({ + description: "Returns Fanavaran damage history status lookup data", + schema: { type: "array", items: { type: "object" } }, + }) + async dmgHistoryStatus() { + return await this.lookupsService.getDmgHistoryStatus(); + } + @Get("inquiry-by-vin") @ApiOperation({ summary: "Fanavaran vehicle inquiry by VIN", diff --git a/src/lookups/lookups.service.ts b/src/lookups/lookups.service.ts index e0910fe..c7eb0fe 100644 --- a/src/lookups/lookups.service.ts +++ b/src/lookups/lookups.service.ts @@ -127,6 +127,22 @@ export class LookupsService { return await this.getClientRemoteLookup("file-types"); } + async getCities(): Promise { + return await this.getClientRemoteLookup("cities"); + } + + async getProvinces(): Promise { + return await this.getClientRemoteLookup("provinces"); + } + + async getDmgCaseType(): Promise { + return await this.getClientRemoteLookup("dmg-case-type"); + } + + async getDmgHistoryStatus(): Promise { + return await this.getClientRemoteLookup("dmg-history-status"); + } + async inquiryByVin(vin: string): Promise { const clientKey = this.activeClientKey(); return this.fanavaranLookupService.inquiryByVin(clientKey, vin); @@ -144,14 +160,70 @@ export class LookupsService { ); } + async mapPolicyDetails(policy: any): Promise { + if (!policy || typeof policy !== "object") { + return policy; + } + + const mappedPolicy = { ...policy }; + + // 1. Map PreviousInsuranceCorpId and TransferorInsuranceCorpId + try { + const companies = (await this.getClientRemoteLookup("insurance-corp")) as any[]; + if (Array.isArray(companies)) { + if (typeof policy.PreviousInsuranceCorpId === "number") { + const match = companies.find((c) => c.Id === policy.PreviousInsuranceCorpId); + if (match) { + mappedPolicy.PreviousInsuranceCorpName = match.Caption; + } + } + if (typeof policy.TransferorInsuranceCorpId === "number") { + const match = companies.find((c) => c.Id === policy.TransferorInsuranceCorpId); + if (match) { + mappedPolicy.TransferorInsuranceCorpName = match.Caption; + } + } + } + } catch (e) { + this.logger.warn(`Failed to map insurance-corp lookups: ${e.message}`); + } + + // 2. Map PolicyUsageTypeId + try { + const useTypes = (await this.getClientRemoteLookup("vehicle-use-types")) as any[]; + if (Array.isArray(useTypes) && typeof policy.PolicyUsageTypeId === "number") { + const match = useTypes.find((t) => t.Id === policy.PolicyUsageTypeId); + if (match) { + mappedPolicy.PolicyUsageTypeName = match.Caption; + } + } + } catch (e) { + this.logger.warn(`Failed to map vehicle-use-types lookups: ${e.message}`); + } + + return mappedPolicy; + } + async thirdPartyPolicyById(policyId: number): Promise { const clientKey = this.activeClientKey(); - return this.fanavaranLookupService.thirdPartyPolicyById(clientKey, policyId); + const policy = await this.fanavaranLookupService.thirdPartyPolicyById(clientKey, policyId); + return this.mapPolicyDetails(policy); } async bodyPolicyById(policyId: number): Promise { const clientKey = this.activeClientKey(); - return this.fanavaranLookupService.bodyPolicyById(clientKey, policyId); + const policy = await this.fanavaranLookupService.bodyPolicyById(clientKey, policyId); + return this.mapPolicyDetails(policy); + } + + async vehicleById(vehicleId: number, versionNo: number = 1): Promise { + const clientKey = this.activeClientKey(); + return this.fanavaranLookupService.vehicleById(clientKey, vehicleId, versionNo); + } + + async customerById(customerId: number): Promise { + const clientKey = this.activeClientKey(); + return this.fanavaranLookupService.customerById(clientKey, customerId); } async getAccidentWay(): Promise<{ id: number; label: string }[]> { diff --git a/src/sms-orchestration/provider/sms-gateway.module.ts b/src/sms-orchestration/provider/sms-gateway.module.ts index fc7cf44..ce36c71 100644 --- a/src/sms-orchestration/provider/sms-gateway.module.ts +++ b/src/sms-orchestration/provider/sms-gateway.module.ts @@ -1,6 +1,7 @@ import { HttpModule } from "@nestjs/axios"; import { Module } from "@nestjs/common"; -import { ConfigModule } from "@nestjs/config"; +import { ConfigModule, ConfigService } from "@nestjs/config"; +import { createHttpModuleOptions } from "src/core/config/http-proxy.factory"; import { KavenegarService } from "./kavenegar.service"; import { KavenegarSmsGateway } from "./kavenegar-sms.gateway"; @@ -8,7 +9,14 @@ import { ParsianSmsGateway } from "./parsian-sms.gateway"; import { SmsGatewayService } from "./sms-gateway.service"; @Module({ - imports: [HttpModule, ConfigModule], + imports: [ + HttpModule.registerAsync({ + imports: [ConfigModule], + inject: [ConfigService], + useFactory: createHttpModuleOptions, + }), + ConfigModule, + ], providers: [ KavenegarService, KavenegarSmsGateway, diff --git a/src/sms-orchestration/sms-orchestration.module.ts b/src/sms-orchestration/sms-orchestration.module.ts index cf671a7..8a02e66 100644 --- a/src/sms-orchestration/sms-orchestration.module.ts +++ b/src/sms-orchestration/sms-orchestration.module.ts @@ -6,10 +6,16 @@ import { SmsGatewayModule } from "./provider/sms-gateway.module"; import { OtpGeneratorService } from "./otp-generator.service"; import { SmsOrchestrationService } from "./sms-orchestration.service"; import { HttpModule } from "@nestjs/axios"; +import { ConfigModule, ConfigService } from "@nestjs/config"; +import { createHttpModuleOptions } from "src/core/config/http-proxy.factory"; @Module({ imports: [ - HttpModule, + HttpModule.registerAsync({ + imports: [ConfigModule], + inject: [ConfigService], + useFactory: createHttpModuleOptions, + }), SmsGatewayModule, MongooseModule.forFeature([{ name: SmsText.name, schema: SmsTextSchema }]), ],