feat: add car inquiries with resilience, ownership privacy, and retry visibility

Introduce plate, chassis, and third-party car endpoints, a wall-clock inquiry
deadline with transport-only retries, and ownership-safe no-match errors so
another person's identity never leaks.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-05 17:21:16 +03:30
co-authored by Cursor
parent b4be98b156
commit 61098f1bf4
40 changed files with 2595 additions and 374 deletions
@@ -0,0 +1,18 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString, Length, Matches } from 'class-validator';
export class CarByChassisRequestDto {
@ApiProperty({ example: '4311402422', description: 'Owner national code (10 digits)' })
@IsString()
@Length(10, 10)
@Matches(/^\d{10}$/, { message: 'nationalCode must be exactly 10 digits' })
nationalCode!: string;
@ApiProperty({
example: 'IRFC89R2VSY976455',
description: 'Vehicle chassis number or VIN',
})
@IsString()
@IsNotEmpty()
chassisNo!: string;
}
@@ -0,0 +1,30 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString, Length, Matches } from 'class-validator';
export class CarByPlateRequestDto {
@ApiProperty({ example: '4311402422', description: 'Owner national code (10 digits)' })
@IsString()
@Length(10, 10)
@Matches(/^\d{10}$/, { message: 'nationalCode must be exactly 10 digits' })
nationalCode!: string;
@ApiProperty({ example: '12', description: 'Two digits on the left side of the plate' })
@IsString()
@Matches(/^\d{2}$/, { message: 'plk1 must be exactly 2 digits' })
plk1!: string;
@ApiProperty({ example: 'ب', description: 'Middle plate letter' })
@IsString()
@IsNotEmpty()
plk2!: string;
@ApiProperty({ example: '345', description: 'Three digits on the right side of the plate' })
@IsString()
@Matches(/^\d{3}$/, { message: 'plk3 must be exactly 3 digits' })
plk3!: string;
@ApiProperty({ example: '67', description: 'Plate serial / region code' })
@IsString()
@IsNotEmpty()
plksrl!: string;
}
+53
View File
@@ -32,6 +32,8 @@ import { RealEstateRequestDto } from './dto/real-estate-request.dto';
import { PolicyByChassisRequestDto } from './dto/policy-by-chassis-request.dto';
import { PolicyByNationalCodeRequestDto } from './dto/policy-by-national-code-request.dto';
import { PolicyByPlateRequestDto } from './dto/policy-by-plate-request.dto';
import { CarByPlateRequestDto } from './dto/car-by-plate-request.dto';
import { CarByChassisRequestDto } from './dto/car-by-chassis-request.dto';
import { InquiryService } from './inquiry.service';
/**
@@ -135,6 +137,57 @@ export class InquiryController {
return this.inquireGeneric(InquiryType.LEGAL_PERSON, payload, req);
}
@Post('carByPlate')
@InquiryAccess(InquiryType.CAR_BY_PLATE)
@Throttle({ default: { limit: 30, ttl: 60000 } })
@ApiOperation({ summary: 'Car insurance inquiry by plate (provider passthrough)' })
@ApiResponse({ status: 200, type: GenericInquiryResponseDto })
async inquireCarByPlate(
@Body() payload: CarByPlateRequestDto,
@Req() req: Request & { requestId?: string; trackingCode?: string },
): Promise<BaseInquiryResponseDto<Record<string, unknown>>> {
return this.inquireGeneric(
InquiryType.CAR_BY_PLATE,
payload as unknown as Record<string, unknown>,
req,
);
}
@Post('carByChassis')
@InquiryAccess(InquiryType.CAR_BY_CHASSIS)
@Throttle({ default: { limit: 30, ttl: 60000 } })
@ApiOperation({ summary: 'Car insurance inquiry by chassis/VIN (provider passthrough)' })
@ApiResponse({ status: 200, type: GenericInquiryResponseDto })
async inquireCarByChassis(
@Body() payload: CarByChassisRequestDto,
@Req() req: Request & { requestId?: string; trackingCode?: string },
): Promise<BaseInquiryResponseDto<Record<string, unknown>>> {
return this.inquireGeneric(
InquiryType.CAR_BY_CHASSIS,
payload as unknown as Record<string, unknown>,
req,
);
}
@Post('thirdPartyCar')
@InquiryAccess(InquiryType.THIRD_PARTY_CAR)
@Throttle({ default: { limit: 30, ttl: 60000 } })
@ApiOperation({
summary:
'Third-party car insurance inquiry with provider-specific selection (Tejarat passthrough, CentInsur partial rules)',
})
@ApiResponse({ status: 200, type: GenericInquiryResponseDto })
async inquireThirdPartyCar(
@Body() payload: CarByPlateRequestDto,
@Req() req: Request & { requestId?: string; trackingCode?: string },
): Promise<BaseInquiryResponseDto<Record<string, unknown>>> {
return this.inquireGeneric(
InquiryType.THIRD_PARTY_CAR,
payload as unknown as Record<string, unknown>,
req,
);
}
@Post('policyByChassis')
@InquiryAccess(InquiryType.POLICY_BY_CHASSIS)
@Throttle({ default: { limit: 30, ttl: 60000 } })
+33 -4
View File
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
import { InquiryType } from '../common/enums/inquiry-type.enum';
import { InquiryStatus } from '../common/enums/inquiry-status.enum';
import { ProviderName } from '../common/enums/provider-name.enum';
import { AttemptSummaryDto } from '../common/dto/attempt-summary.dto';
import { BaseInquiryResponseDto } from '../common/dto/base-inquiry-response.dto';
import { NormalizedErrorDto } from '../common/dto/normalized-error.dto';
import { generateTrackingCode } from '../common/helpers/tracking-code.helper';
@@ -10,9 +11,9 @@ import { InquiryException } from '../common/exceptions/inquiry.exception';
import { InquiryLogService } from '../logging/inquiry-log.service';
import { translateError } from '../common/helpers/translate-error.helper';
import { buildNormalizedError } from '../common/constants/error-messages';
import { shouldExposeAttemptSummary } from '../common/helpers/provider-resilience.helper';
import {
LegacyInquiryPayload,
PersonInquiryPayload,
PersonInquiryResult,
} from '../providers/shared/legacy-api.provider.abstract';
import { ProviderOrchestratorService } from '../providers/strategy/provider-orchestrator.service';
@@ -57,6 +58,8 @@ export class InquiryService {
trackingCode,
);
const attemptSummary = this.resolveExposedSummary(true, result.attemptSummary);
const response = buildInquiryResponse({
success: true,
provider: result.provider,
@@ -64,6 +67,7 @@ export class InquiryService {
message: `${this.getInquiryLabel(inquiryType)} completed successfully`,
duration: result.duration,
data: this.toResponseData(result.data),
attemptSummary,
});
await this.persistLog({
@@ -75,12 +79,15 @@ export class InquiryService {
duration: result.duration,
requestId,
trackingCode,
attemptSummary: result.attemptSummary,
});
return response;
} catch (error) {
const duration = Date.now() - start;
const { normalized, provider } = this.extractFailure(error);
const { normalized, provider, attemptSummary } = this.extractFailure(error, duration);
const exposedSummary = this.resolveExposedSummary(false, attemptSummary);
const response = buildInquiryResponse({
success: false,
@@ -89,6 +96,7 @@ export class InquiryService {
message: normalized.message,
duration,
error: normalized,
attemptSummary: exposedSummary,
});
await this.persistLog({
@@ -100,6 +108,7 @@ export class InquiryService {
requestId,
trackingCode,
error: normalized as unknown as Record<string, unknown>,
attemptSummary,
}).catch(() => undefined);
return response;
@@ -118,6 +127,13 @@ export class InquiryService {
});
}
private resolveExposedSummary(
success: boolean,
summary: AttemptSummaryDto | undefined,
): AttemptSummaryDto | undefined {
return shouldExposeAttemptSummary(success, summary) ? summary : undefined;
}
private toResponseData(result: unknown): Record<string, unknown> {
if (this.isPersonInquiryResult(result)) {
const raw =
@@ -156,12 +172,25 @@ export class InquiryService {
return inquiryType.replace(/_INQUIRY$/, '').toLowerCase().replace(/_/g, ' ');
}
private extractFailure(error: unknown): {
private extractFailure(
error: unknown,
durationMs: number,
): {
normalized: NormalizedErrorDto;
provider?: string;
attemptSummary?: AttemptSummaryDto;
} {
if (error instanceof InquiryException) {
return { normalized: translateError(error.normalizedError), provider: error.provider };
return {
normalized: translateError(error.normalizedError),
provider: error.provider,
attemptSummary: error.attemptSummary ?? {
totalAttempts: 0,
retried: false,
durationMs,
attempts: [],
},
};
}
if (error && typeof error === 'object' && 'normalizedError' in error) {
return {