1
0
forked from Yara724/api

YARA-836 + 2 more sms

This commit is contained in:
SepehrYahyaee
2026-04-25 16:53:56 +03:30
parent 9c87927e6c
commit 5d2227b00b
7 changed files with 156 additions and 4 deletions

View File

@@ -13,6 +13,7 @@ import { ClientModule } from "src/client/client.module";
import { ExpertBlameModule } from "src/expert-blame/expert-blame.module";
import { RequestManagementModule } from "src/request-management/request-management.module";
import { SandHubModule } from "src/sand-hub/sand-hub.module";
import { SmsOrchestrationModule } from "src/sms-orchestration/sms-orchestration.module";
import { UsersModule } from "src/users/users.module";
import { ExpertClaimController } from "./expert-claim.controller";
import { ExpertClaimV2Controller } from "./expert-claim.v2.controller";
@@ -31,6 +32,7 @@ import { ExpertClaimService } from "./expert-claim.service";
ExpertBlameModule,
AiModule,
RequestManagementModule,
SmsOrchestrationModule,
UsersModule,
ClientModule,
],

View File

@@ -65,6 +65,7 @@ import {
import { resendRequestHasPayload } from "src/helpers/claim-expert-resend";
import { snapshotFromDamageExpert } from "src/helpers/expert-profile-snapshot";
import { DamageExpertModel } from "src/users/entities/schema/damage-expert.schema";
import { SmsOrchestrationService } from "src/sms-orchestration/sms-orchestration.service";
@Injectable()
export class ExpertClaimService {
@@ -187,6 +188,7 @@ export class ExpertClaimService {
private readonly claimFactorsImageDbService: ClaimFactorsImageDbService,
private readonly claimRequiredDocumentDbService: ClaimRequiredDocumentDbService,
private readonly branchDbService: BranchDbService,
private readonly smsOrchestrationService: SmsOrchestrationService,
) { }
/** Load immutable profile fields from `damage-expert` for the acting expert. */
@@ -282,13 +284,16 @@ export class ExpertClaimService {
private blameFileContextForExpert(blame: any): {
blameRequestType?: BlameRequestType;
carBodyFirstForm?: { car?: boolean; object?: boolean };
blameStatus?: string
} {
if (!blame?.type) return {};
const blameRequestType = blame.type as BlameRequestType;
const out: {
blameRequestType?: BlameRequestType;
carBodyFirstForm?: { car?: boolean; object?: boolean };
blameStatus?: string;
} = { blameRequestType };
out.blameStatus = blame.blameStatus;
if (blameRequestType !== BlameRequestType.CAR_BODY) return out;
const parties = blame.parties;
@@ -297,6 +302,7 @@ export class ExpertClaimService {
const first =
parties.find((p: any) => p?.role === PartyRole.FIRST) ?? parties[0];
const cbf = first?.carBodyFirstForm;
delete out.blameStatus
if (cbf && typeof cbf === "object") {
out.carBodyFirstForm = {
...(typeof cbf.car === "boolean" ? { car: cbf.car } : {}),
@@ -2219,6 +2225,30 @@ export class ExpertClaimService {
},
});
if (claim.blameRequestId) {
const blame = await this.blameRequestDbService.findById(
claim.blameRequestId.toString(),
);
if (blame?.type === BlameRequestType.THIRD_PARTY) {
const ownerUserId = claim.owner?.userId ? String(claim.owner.userId) : "";
const ownerParty = (blame.parties || []).find(
(p: any) =>
p?.person?.userId && String(p.person.userId) === ownerUserId,
);
const ownerPhone = ownerParty?.person?.phoneNumber;
if (ownerPhone && typeof ownerPhone === "string") {
await this.smsOrchestrationService.sendResendDocumentsNotice({
receptor: ownerPhone,
fileKind: "claim",
publicId: claim.publicId,
link: this.smsOrchestrationService.buildClaimLink(
String(claim._id),
),
});
}
}
}
return {
claimRequestId,
status: ClaimCaseStatus.WAITING_FOR_USER_RESEND,
@@ -2371,6 +2401,33 @@ export class ExpertClaimService {
await this.claimCaseDbService.findByIdAndUpdate(claimRequestId, updatePayload);
if (!needsFactorUpload && claim.blameRequestId) {
const blame = await this.blameRequestDbService.findById(
claim.blameRequestId.toString(),
);
if (blame?.type === BlameRequestType.THIRD_PARTY) {
const ownerUserId = claim.owner?.userId ? String(claim.owner.userId) : "";
const ownerParty = (blame.parties || []).find(
(p: any) =>
p?.person?.userId && String(p.person.userId) === ownerUserId,
);
const ownerPhone = ownerParty?.person?.phoneNumber;
if (ownerPhone && typeof ownerPhone === "string") {
const expertLastName =
actor?.fullName?.trim()?.split(/\s+/).pop() || "کارشناس";
await this.smsOrchestrationService.sendSignatureReviewNotice({
receptor: ownerPhone,
fileKind: "claim",
publicId: claim.publicId,
expertLastName,
link: this.smsOrchestrationService.buildClaimLink(
String(claim._id),
),
});
}
}
}
return {
claimRequestId,
status: nextCaseStatus,
@@ -2519,7 +2576,7 @@ export class ExpertClaimService {
blameIds.length > 0
? ((await this.blameRequestDbService.find(
{ _id: { $in: blameIds.map((id) => new Types.ObjectId(id)) } },
{ lean: true, select: "type parties expert.decision" },
{ lean: true, select: "type parties expert.decision blameStatus" },
)) as any[])
: [];
const blameById = new Map<string, any>(