forked from Yara724/api
Added extra fanavaran fields
This commit is contained in:
@@ -58,6 +58,11 @@ import {
|
||||
fanavaranHullNestedClaimId,
|
||||
toFanavaranHullBaseClaimPayload,
|
||||
} from "./fanavaran-hull-base-claim";
|
||||
import {
|
||||
activeStageLookupRows, applyFanavaranStageFieldReview,
|
||||
fanavaranFieldStageSent, fanavaranStageFields,
|
||||
type FanavaranFieldValues,
|
||||
} from "./fanavaran-stage-fields";
|
||||
import {
|
||||
collectFanavaranExpertiseReadinessWarnings,
|
||||
hullExpertiseAssertFields,
|
||||
@@ -4395,7 +4400,8 @@ export class ClaimRequestManagementService {
|
||||
vehicleCurrentValue = vehicleCurrentValueFromHullPolicyRecord(policy);
|
||||
}
|
||||
|
||||
const repairDuration = FANAVARAN_DEFAULT_HULL_REPAIR_DURATION;
|
||||
vehicleCurrentValue = input.claimCase?.fanavaranFieldReview?.values?.VehicleCurrentValue ?? vehicleCurrentValue;
|
||||
const repairDuration = input.claimCase?.fanavaranFieldReview?.values?.RepairDuration ?? FANAVARAN_DEFAULT_HULL_REPAIR_DURATION;
|
||||
|
||||
return {
|
||||
replyKey: input.replyKey,
|
||||
@@ -4757,7 +4763,7 @@ export class ClaimRequestManagementService {
|
||||
"shsNam",
|
||||
]) ??
|
||||
(typeof apiVehicle?.ChassisNo === "string" ? apiVehicle.ChassisNo : null),
|
||||
DmgHistoryStatus: input.defaults.DmgHistoryStatus,
|
||||
DmgHistoryStatus: input.claimCase?.fanavaranFieldReview?.values?.DmgHistoryStatus ?? input.defaults.DmgHistoryStatus,
|
||||
Desc: this.formatFanavaranSelectedPartsDesc(input.selectedParts),
|
||||
DmgCaseTypeId: input.defaults.DmgCaseTypeId,
|
||||
DriverId: driverFanavaranId ?? null,
|
||||
@@ -6189,12 +6195,17 @@ export class ClaimRequestManagementService {
|
||||
logPrefix,
|
||||
claimCaseId,
|
||||
});
|
||||
applyFanavaranStageFieldReview(payload, claimCase, "car-body", "baseClaim");
|
||||
delete payload.IsLicenseReplacement;
|
||||
const hull = toFanavaranHullBaseClaimPayload(payload);
|
||||
for (const key of Object.keys(payload)) delete payload[key];
|
||||
Object.assign(payload, hull);
|
||||
}
|
||||
|
||||
if (fanavaranClaimProductFromBlameType(blameCase.type) === "third-party") {
|
||||
applyFanavaranStageFieldReview(payload, claimCase, "third-party", "baseClaim");
|
||||
}
|
||||
|
||||
const fileRoleExpertIds =
|
||||
await this.resolveFanavaranFileRoleExpertIdsForBlame(blameCase);
|
||||
if (fileRoleExpertIds) {
|
||||
@@ -6983,6 +6994,93 @@ export class ClaimRequestManagementService {
|
||||
return definition;
|
||||
}
|
||||
|
||||
/** Read-only panel context. Does not create a remote claim or persist a preview. */
|
||||
async getFanavaranStageFieldsContext(claim: any, blame: any) {
|
||||
if (!blame || !isFanavaranSubmitSupportedBlameType(blame.type)) {
|
||||
throw new BadRequestException(
|
||||
"Fanavaran field review only applies to third-party and car-body claims.",
|
||||
);
|
||||
}
|
||||
const product = fanavaranClaimProductFromBlameType(blame.type);
|
||||
const clientKey = resolveFanavaranClientKey();
|
||||
const defaults = getFanavaranClientProfile(clientKey).defaults;
|
||||
const definitions = fanavaranStageFields(product);
|
||||
const options = new Map<string, ReturnType<typeof activeStageLookupRows>>();
|
||||
await Promise.all(
|
||||
definitions
|
||||
.filter((field) => field.lookup)
|
||||
.map(async (field) => {
|
||||
options.set(
|
||||
field.lookup,
|
||||
activeStageLookupRows(
|
||||
await this.getFanavaranLookupRows(clientKey, field.lookup),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
const initial: FanavaranFieldValues = {
|
||||
AccidentLocationAddress: FANAVARAN_ACCIDENT_LOCATION_ADDRESS,
|
||||
AccidentCityId: defaults.AccidentCityId,
|
||||
AccidentReportTypeId: defaults.AccidentReportTypeId,
|
||||
DmgHistoryStatus: defaults.DmgHistoryStatus,
|
||||
InspectionPlaceId: 282,
|
||||
AccidentTypeId: 2,
|
||||
CulpritTypeId: 300,
|
||||
AuthorityCulpritId: authorityCulpritIdFromDetectionRows(
|
||||
options.get("detection-accident-culprits") ?? [],
|
||||
),
|
||||
CustomerFaultPercent: FANAVARAN_DEFAULT_HULL_CUSTOMER_FAULT_PERCENT,
|
||||
RepairDuration: FANAVARAN_DEFAULT_HULL_REPAIR_DURATION,
|
||||
};
|
||||
if (product === "car-body") {
|
||||
const price =
|
||||
this.parseFanavaranMoney(claim?.vehicle?.carPrice) ||
|
||||
this.parseFanavaranMoney(claim?.vehicle?.price) ||
|
||||
this.parseFanavaranMoney(claim?.evaluation?.priceDrop?.carPrice) ||
|
||||
(await this.resolveHullVehicleCurrentValueFromPolicy(clientKey, claim));
|
||||
if (price > 0) initial.VehicleCurrentValue = price;
|
||||
}
|
||||
return {
|
||||
product,
|
||||
version: claim.fanavaranFieldReview?.version ?? 0,
|
||||
reviewedAt: claim.fanavaranFieldReview?.reviewedAt,
|
||||
reviewedByActorName: claim.fanavaranFieldReview?.reviewedByActorName,
|
||||
fields: definitions.map((field) => {
|
||||
const sent = fanavaranFieldStageSent(claim, field.stage);
|
||||
const sentValue = sent
|
||||
? claim.fanavaranSync?.[field.stage]?.lastPayload?.[field.key]
|
||||
: undefined;
|
||||
const reviewedValue = claim.fanavaranFieldReview?.values?.[field.key];
|
||||
const value = sentValue ?? reviewedValue ?? initial[field.key] ?? null;
|
||||
const rows = field.lookup
|
||||
? (options.get(field.lookup) ?? [])
|
||||
: undefined;
|
||||
return {
|
||||
...field,
|
||||
value,
|
||||
source:
|
||||
sentValue != null
|
||||
? "submitted"
|
||||
: reviewedValue != null
|
||||
? "reviewed"
|
||||
: "default",
|
||||
editable: !sent,
|
||||
...(field.lookup
|
||||
? {
|
||||
options: rows,
|
||||
lookupUnavailable: !rows.length,
|
||||
caption:
|
||||
rows.find((row) => row.Id === value)?.Caption ??
|
||||
(reviewedValue === value
|
||||
? claim.fanavaranFieldReview?.captions?.[field.key]
|
||||
: undefined),
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
private async getFanavaranLookupRows(
|
||||
clientKey: FanavaranClientKey,
|
||||
name: string,
|
||||
@@ -6994,7 +7092,11 @@ export class ClaimRequestManagementService {
|
||||
definition.url,
|
||||
definition.cacheFile,
|
||||
);
|
||||
return Array.isArray(data) ? data : [];
|
||||
let rows: unknown = data;
|
||||
for (let level = 0; level < 3 && rows && !Array.isArray(rows) && typeof rows === "object"; level++) {
|
||||
rows = (rows as { data?: unknown }).data;
|
||||
}
|
||||
return Array.isArray(rows) ? rows : [];
|
||||
} catch {
|
||||
this.logger.warn(
|
||||
`Lookup "${name}" unavailable for ${clientKey}; returning empty.`,
|
||||
@@ -7239,7 +7341,7 @@ export class ClaimRequestManagementService {
|
||||
|
||||
const priceDrop = input.claimCase.evaluation?.priceDrop ?? {};
|
||||
const priceDropTotal = this.parseFanavaranMoney(priceDrop?.total);
|
||||
const inspectionPlaceId = 282;
|
||||
const inspectionPlaceId = input.claimCase?.fanavaranFieldReview?.values?.InspectionPlaceId ?? 282;
|
||||
const dropAmountStatus = 5458;
|
||||
|
||||
const dmgSections = parts.map((part) =>
|
||||
|
||||
Reference in New Issue
Block a user