Merge pull request 'Fix PDF return data' (#280) from s.yahyaee/yara724-api:main into main

Reviewed-on: Yara724/api#280
This commit is contained in:
2026-08-31 12:32:00 +03:30
3 changed files with 48 additions and 11 deletions

View File

@@ -39,6 +39,8 @@ describe("buildInsurerFileReport", () => {
userId: "guilty-user-id",
fullName: "مقصر نمونه",
phoneNumber: "09120000000",
nationalCodeOfInsurer: "0987654321",
insurerBirthday: 13650115,
clientId: "client-guilty",
},
statement: {
@@ -155,6 +157,13 @@ describe("buildInsurerFileReport", () => {
},
});
expect(getFieldValue(report, PR.ownerSection, PR.name)).toBe("زیان دیده نمونه");
expect(getFieldValue(report, PR.guiltyOwnerSection, PR.name)).toBe("مقصر نمونه");
expect(getFieldValue(report, PR.guiltyOwnerSection, PR.phone)).toBe("09120000000");
expect(getFieldValue(report, PR.guiltyOwnerSection, PR.nationalCode)).toBe(
"0987654321",
);
expect(getFieldValue(report, PR.damagedThirdPartyInsuranceSection, PR.policyNumber)).toBe(
"TP-DAMAGED-001",
);

View File

@@ -477,28 +477,48 @@ function buildCarBodyInsuranceFields(
];
}
function buildOwnerSection(
damagedParty: ReportParty | null,
claim?: Record<string, unknown> | null,
): InsurerFileReportSection {
const person = damagedParty?.person as ReportRecord | undefined;
function buildPartyOwnerSection(
title: string,
party: ReportParty | null | undefined,
options?: {
claim?: Record<string, unknown> | null;
useClaimOwnerFallback?: boolean;
includeSheba?: boolean;
},
): InsurerFileReportSection | undefined {
const person = party?.person as ReportRecord | undefined;
const claim = options?.claim;
const money = claim?.money as
| { sheba?: string; nationalCodeOfInsurer?: string }
| undefined;
const claimOwner = claim?.owner as { fullName?: string } | undefined;
return buildSection(PR.ownerSection, [
{ label: PR.name, value: firstDefined(person?.fullName, claimOwner?.fullName) },
if (!person && !options?.useClaimOwnerFallback) return undefined;
return buildSection(title, [
{
label: PR.name,
value: options?.useClaimOwnerFallback
? firstDefined(person?.fullName, claimOwner?.fullName)
: firstDefined(person?.fullName),
},
{ label: PR.phone, value: asString(person?.phoneNumber) },
{
label: PR.nationalCode,
value: firstDefined(person?.nationalCodeOfInsurer, money?.nationalCodeOfInsurer),
value: options?.useClaimOwnerFallback
? firstDefined(person?.nationalCodeOfInsurer, money?.nationalCodeOfInsurer)
: firstDefined(person?.nationalCodeOfInsurer, person?.nationalCode),
},
{
label: PR.birthDate,
value: formatBirthDate(person?.insurerBirthday ?? person?.birthday),
value: formatBirthDate(
person?.insurerBirthday ?? person?.birthday ?? person?.driverBirthday,
),
},
{
label: PR.sheba,
value: options?.includeSheba ? money?.sheba : undefined,
},
{ label: PR.sheba, value: money?.sheba },
]);
}
@@ -838,7 +858,14 @@ export function buildInsurerFileReport(file: {
const sections = filterEmptySections([
buildCaseTimelineSection(overview, claim),
buildOwnerSection(damagedParty, claim),
buildPartyOwnerSection(PR.ownerSection, damagedParty, {
claim,
useClaimOwnerFallback: true,
includeSheba: true,
}),
includeGuiltySections
? buildPartyOwnerSection(PR.guiltyOwnerSection, guiltyParty)
: undefined,
buildDriverSection(damagedParty, blameContext),
buildSection(
PR.damagedThirdPartyInsuranceSection,

View File

@@ -4,6 +4,7 @@ export const PR = {
requestNo: "شماره درخواست",
empty: "-",
ownerSection: "مالک خودروی زیان دیده",
guiltyOwnerSection: "مالک خودروی مقصر",
driverSection: "راننده خودروی زیان دیده",
damagedThirdPartyInsuranceSection: "بیمه شخص ثالث زیان‌دیده",
damagedCarBodyInsuranceSection: "بیمه بدنه زیان‌دیده",