forked from Yara724/api
feat(depreciation): apply Fanavaran tables and age eligibility
Use the supplied part, severity and age codes for depreciation. Exclude vehicles older than ten from calculated and manual amounts, preserve historical assessments, and send zero depreciation to Fanavaran for ineligible vehicles.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { resolveClaimPriceDropAge } from "src/helpers/claim-price-drop";
|
||||
import { unlink } from "node:fs/promises";
|
||||
import { plainToInstance } from "class-transformer";
|
||||
import { validateSync } from "class-validator";
|
||||
@@ -6331,7 +6332,9 @@ export class ClaimRequestManagementService {
|
||||
}
|
||||
|
||||
const priceDrop = input.claimCase.evaluation?.priceDrop ?? {};
|
||||
const priceDropTotal = this.parseFanavaranMoney(priceDrop?.total);
|
||||
const priceDropVehicleAge = resolveClaimPriceDropAge(input.claimCase, blameForExpertIds);
|
||||
const priceDropTotal = priceDropVehicleAge != null && priceDropVehicleAge > 10
|
||||
? 0 : this.parseFanavaranMoney(priceDrop?.total);
|
||||
const submittedAt = reply?.submittedAt ?? new Date();
|
||||
const product = await this.resolveFanavaranClaimProduct(
|
||||
input.claimCase?._id ? String(input.claimCase._id) : undefined,
|
||||
|
||||
@@ -276,6 +276,27 @@ export const ClaimFileRatingSchema =
|
||||
|
||||
@Schema({ _id: false })
|
||||
export class ClaimPriceDrop {
|
||||
@Prop({ type: Boolean })
|
||||
eligible?: boolean;
|
||||
|
||||
@Prop({ type: String })
|
||||
exclusionReason?: string;
|
||||
|
||||
@Prop({ type: Boolean })
|
||||
manualOverride?: boolean;
|
||||
|
||||
@Prop({ type: String })
|
||||
calculationVersion?: string;
|
||||
|
||||
@Prop({ type: Number })
|
||||
vehicleAge?: number;
|
||||
|
||||
@Prop({ type: Number })
|
||||
fanavaranAgeId?: number;
|
||||
|
||||
@Prop({ type: Number })
|
||||
accidentYear?: number;
|
||||
|
||||
@Prop({ type: Number })
|
||||
total?: number;
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import { ClaimRequestManagementService } from "./claim-request-management.service";
|
||||
|
||||
describe("Fanavaran depreciation age eligibility", () => {
|
||||
it.each(
|
||||
["car-body", "third-party"].flatMap((product) =>
|
||||
[10, 11].map((age) => ({ product, age })),
|
||||
),
|
||||
)(
|
||||
"$product: age $age uses the eligible total only",
|
||||
async ({ product, age }) => {
|
||||
const service = Object.create(
|
||||
ClaimRequestManagementService.prototype,
|
||||
) as any;
|
||||
const first = {
|
||||
role: "FIRST",
|
||||
person: { userId: "first" },
|
||||
statement: { accidentDate: "2026-11-23" },
|
||||
vehicle: { inquiry: { mapped: { ModelField: String(1405 - age) } } },
|
||||
};
|
||||
const second = {
|
||||
role: "SECOND",
|
||||
person: { userId: "second" },
|
||||
vehicle: first.vehicle,
|
||||
};
|
||||
const blame =
|
||||
product === "car-body"
|
||||
? { type: "CAR_BODY", parties: [first] }
|
||||
: {
|
||||
type: "THIRD_PARTY",
|
||||
parties: [first, second],
|
||||
expert: { decision: { guiltyPartyId: "first" } },
|
||||
};
|
||||
service.blameRequestDbService = {
|
||||
findById: jest.fn().mockResolvedValue(blame),
|
||||
};
|
||||
service.tryResolveFanavaranExpertiseClaimExpertId = jest
|
||||
.fn()
|
||||
.mockResolvedValue({ claimExpertId: 4044 });
|
||||
service.resolveFanavaranClaimProduct = jest
|
||||
.fn()
|
||||
.mockResolvedValue(product);
|
||||
service.getFanavaranLookupRows = jest.fn().mockResolvedValue([]);
|
||||
service.buildCarBodyFanavaranExpertisePayload = jest.fn(
|
||||
async (input) => ({ payload: { DropAmount: input.priceDropTotal } }),
|
||||
);
|
||||
const claimCase = {
|
||||
_id: "claim",
|
||||
blameRequestId: "blame",
|
||||
owner: { userId: "first" },
|
||||
evaluation: { priceDrop: { total: 999, carPrice: 400000000 } },
|
||||
};
|
||||
const result = await service.buildFanavaranExpertisePayload({
|
||||
claimCase,
|
||||
clientKey: "parsian",
|
||||
});
|
||||
expect(
|
||||
result.payload[
|
||||
product === "car-body"
|
||||
? "DropAmount"
|
||||
: "DropAmountAdditionsDeductions"
|
||||
],
|
||||
).toBe(age > 10 ? 0 : 999);
|
||||
expect(claimCase.evaluation.priceDrop.total).toBe(999); // Historical data is preserved.
|
||||
},
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user