sms template corrected and now fires at the end of the fanavaran stage (Expertise). Docs also added.

This commit is contained in:
2026-08-18 11:18:33 +03:30
parent cb69b496b5
commit 693d602e49
11 changed files with 68 additions and 44 deletions

View File

@@ -5918,6 +5918,13 @@ 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]`,
});
return (
(claimCase as any)?.fanavaranSync?.expertise?.response ?? {
Id: claimCase.expertiseId,
@@ -5982,6 +5989,14 @@ 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]`,
});
return response.data;
} catch (error) {
const exchange = this.fanavaranAuditService.captureAxiosExchange(error);
@@ -6018,6 +6033,12 @@ export class ClaimRequestManagementService {
};
}
if (claimCase.expertiseId != null) {
await this.notifyClaimOwnerFanavaranClaimRegistered({
claimCaseId,
claimId: claimCase.claimId,
claimNo: claimCase.claimNo,
logPrefix,
});
return {
attempted: false,
submitted: false,
@@ -7083,11 +7104,11 @@ export class ClaimRequestManagementService {
}
/**
* After Fanavaran base claim create succeeds, SMS the claim owner with
* ClaimNo + claimId. Uses SmsOrchestrationService → same provider as login
* for this deployment (`SMS` / `SMS_PROVIDER`). Never throws.
* 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 notifyClaimOwnerFanavaranBaseClaimRegistered(input: {
private async notifyClaimOwnerFanavaranClaimRegistered(input: {
claimCaseId: string;
claimId?: number | string | null;
claimNo?: number | string | null;
@@ -7106,7 +7127,9 @@ export class ClaimRequestManagementService {
);
if (!claimCase) return;
if ((claimCase as any)?.fanavaranSync?.baseClaim?.smsNotifiedAt) {
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`,
);
@@ -7127,23 +7150,21 @@ export class ClaimRequestManagementService {
: String(input.claimCaseId);
const sent =
await this.smsOrchestrationService.sendFanavaranBaseClaimRegisteredNotice(
{
receptor: phone,
publicId,
claimNo: input.claimNo,
claimId: input.claimId,
},
);
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.baseClaim.smsNotifiedAt": new Date(),
"fanavaranSync.expertise.smsNotifiedAt": new Date(),
},
});
this.logger.log(
`${input.logPrefix} Fanavaran claim SMS sent to claim owner phone=${phone} claimNo=${input.claimNo ?? "-"} claimId=${input.claimId ?? "-"}`,
`${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) {
@@ -7301,14 +7322,6 @@ export class ClaimRequestManagementService {
claimCaseId,
updateData,
);
// Best-effort: same SMS provider as login for this deployment
await this.notifyClaimOwnerFanavaranBaseClaimRegistered({
claimCaseId,
claimId,
claimNo,
logPrefix,
});
}
return response.data;

View File

@@ -107,7 +107,7 @@ export class FanavaranSyncStage {
@Prop({ type: Date })
lastPayloadBuiltAt?: Date;
/** When we SMS'd the claim owner about Fanavaran claimId/ClaimNo (base claim). */
/** When we SMS'd the claim owner about Fanavaran claimId/ClaimNo (after expertise). */
@Prop({ type: Date })
smsNotifiedAt?: Date;