fix inquiry integration and insurer case details

This commit is contained in:
SepehrYahyaee
2026-09-19 16:06:04 +03:30
parent cd36a0f2d4
commit 8071215803
18 changed files with 141 additions and 167 deletions

View File

@@ -249,7 +249,6 @@ import {
FanavaranAuditStatus,
FanavaranAuditStep,
} from "src/fanavaran/schema/fanavaran-audit-log.schema";
import { SmsOrchestrationService } from "src/sms-orchestration/sms-orchestration.service";
import { selectLatestActiveFanavaranPolicy } from "./fanavaran-policy-selection";
import {
selectAccidentVehicleUsedId,
@@ -487,7 +486,6 @@ export class ClaimRequestManagementService {
private readonly fanavaranAuditService: FanavaranAuditService,
private readonly fanavaranAuthService: FanavaranAuthService,
private readonly fanavaranLookupService: FanavaranLookupService,
private readonly smsOrchestrationService: SmsOrchestrationService,
private readonly fileMakerDbService: FileMakerDbService,
private readonly fileReviewerDbService: FileReviewerDbService,
private readonly fieldExpertDbService: FieldExpertDbService,
@@ -7395,13 +7393,7 @@ export class ClaimRequestManagementService {
this.logger.log(
`[executeFanavaranExpertiseSubmit] Already have expertiseId=${claimCase.expertiseId}; skipping Fanavaran POST`,
);
// Catch-up / deduped: SMS may still be pending if expertise predated this notify.
await this.notifyClaimOwnerFanavaranClaimRegistered({
claimCaseId,
claimId: claimCase.claimId,
claimNo: claimCase.claimNo,
logPrefix: `[Fanavaran ${clientKey} V2 Expertise]`,
});
// Product decision: completing the final Fanavaran stage must not send SMS.
return (
(claimCase as any)?.fanavaranSync?.expertise?.response ?? {
Id: claimCase.expertiseId,
@@ -7477,13 +7469,7 @@ export class ClaimRequestManagementService {
},
});
// Best-effort: SMS after last Fanavaran stage (expertise) succeeds
await this.notifyClaimOwnerFanavaranClaimRegistered({
claimCaseId,
claimId: claimCase.claimId,
claimNo: claimCase.claimNo,
logPrefix: `[Fanavaran ${clientKey} V2 Expertise]`,
});
// Product decision: completing the final Fanavaran stage must not send SMS.
return response.data;
} catch (error) {
@@ -7521,12 +7507,7 @@ export class ClaimRequestManagementService {
};
}
if (claimCase.expertiseId != null) {
await this.notifyClaimOwnerFanavaranClaimRegistered({
claimCaseId,
claimId: claimCase.claimId,
claimNo: claimCase.claimNo,
logPrefix,
});
// Product decision: an already-completed Fanavaran stage must not send SMS.
return {
attempted: false,
submitted: false,
@@ -8695,111 +8676,6 @@ export class ClaimRequestManagementService {
return true;
}
/**
* Phone for the claim owner / damaged party (same recipient as other claim SMS).
*/
private async resolveFanavaranClaimOwnerPhone(
claimCase: any,
): Promise<string | undefined> {
const notifyUserId =
claimCase?.damagedPartyUserId ?? claimCase?.owner?.userId;
if (!notifyUserId) return undefined;
const ownerUserId = String(notifyUserId);
if (claimCase.blameRequestId) {
const blame = await this.blameRequestDbService.findById(
String(claimCase.blameRequestId),
);
const ownerParty = (blame?.parties || []).find(
(p: any) =>
p?.person?.userId && String(p.person.userId) === ownerUserId,
);
const fromParty = ownerParty?.person?.phoneNumber;
if (typeof fromParty === "string" && fromParty.trim()) {
return fromParty.trim();
}
}
const user = await this.userDbService.findOne({
_id: new Types.ObjectId(ownerUserId),
});
const mobile = user?.mobile;
if (typeof mobile === "string" && mobile.trim()) return mobile.trim();
return undefined;
}
/**
* After Fanavaran expertise (last stage) succeeds, SMS the claim owner with
* publicId + claimId + ClaimNo. Uses SmsOrchestrationService → same provider
* as login for this deployment (`SMS` / `SMS_PROVIDER`). Never throws.
*/
private async notifyClaimOwnerFanavaranClaimRegistered(input: {
claimCaseId: string;
claimId?: number | string | null;
claimNo?: number | string | null;
logPrefix: string;
}): Promise<void> {
try {
if (input.claimId == null && input.claimNo == null) {
this.logger.warn(
`${input.logPrefix} Skip Fanavaran SMS: no claimId/ClaimNo on response`,
);
return;
}
const claimCase = await this.claimCaseDbService.findById(
input.claimCaseId,
);
if (!claimCase) return;
const sync = (claimCase as any)?.fanavaranSync;
// Dedup: expertise stage, or older base-claim notify from before the move.
if (sync?.expertise?.smsNotifiedAt || sync?.baseClaim?.smsNotifiedAt) {
this.logger.log(
`${input.logPrefix} Fanavaran SMS already sent; skipping duplicate`,
);
return;
}
const phone = await this.resolveFanavaranClaimOwnerPhone(claimCase);
if (!phone) {
this.logger.warn(
`${input.logPrefix} Skip Fanavaran SMS: no phone for claim owner`,
);
return;
}
const publicId =
typeof claimCase.publicId === "string" && claimCase.publicId.trim()
? claimCase.publicId.trim()
: String(input.claimCaseId);
const sent =
await this.smsOrchestrationService.sendFanavaranClaimRegisteredNotice({
receptor: phone,
publicId,
claimNo: input.claimNo ?? claimCase.claimNo,
claimId: input.claimId ?? claimCase.claimId,
});
if (sent) {
await this.claimCaseDbService.findByIdAndUpdate(input.claimCaseId, {
$set: {
"fanavaranSync.expertise.smsNotifiedAt": new Date(),
},
});
this.logger.log(
`${input.logPrefix} Fanavaran claim SMS sent to claim owner phone=${phone} publicId=${publicId} claimNo=${input.claimNo ?? claimCase.claimNo ?? "-"} claimId=${input.claimId ?? claimCase.claimId ?? "-"}`,
);
}
} catch (error) {
this.logger.error(
`${input.logPrefix} Fanavaran claim SMS failed (non-fatal)`,
error,
);
}
}
private async executeFanavaranV2Submit(
claimCaseId: string,
clientKey: FanavaranClientKey,