forked from Yara724/api
Added factorLink and branchName support
This commit is contained in:
@@ -1900,6 +1900,90 @@ export class ClaimRequestManagementService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* V2 response mapper:
|
||||
* - convert factorLink ObjectId -> public URL
|
||||
* - enrich daghi.branchId with branchName when available
|
||||
*/
|
||||
private async mapEvaluationForClient(evaluation: any): Promise<any | undefined> {
|
||||
if (!evaluation) return undefined;
|
||||
|
||||
const mapReply = async (reply: any) => {
|
||||
if (!reply) return reply;
|
||||
|
||||
const mapped = {
|
||||
...(typeof reply?.toObject === "function" ? reply.toObject() : reply),
|
||||
};
|
||||
const parts = Array.isArray(mapped.parts) ? mapped.parts : [];
|
||||
|
||||
const factorIds = new Set<string>();
|
||||
const branchIds = new Set<string>();
|
||||
for (const p of parts) {
|
||||
if (p?.factorLink && Types.ObjectId.isValid(String(p.factorLink))) {
|
||||
factorIds.add(String(p.factorLink));
|
||||
}
|
||||
const daghi = p?.daghi;
|
||||
const rawBranchId =
|
||||
daghi && typeof daghi === "object" ? (daghi as any).branchId : undefined;
|
||||
if (rawBranchId && Types.ObjectId.isValid(String(rawBranchId))) {
|
||||
branchIds.add(String(rawBranchId));
|
||||
}
|
||||
}
|
||||
|
||||
const factorMap = new Map<string, string>();
|
||||
await Promise.all(
|
||||
Array.from(factorIds).map(async (id) => {
|
||||
const factorDoc = await this.claimFactorsImageDbService.findById(id);
|
||||
if (factorDoc?.path) {
|
||||
factorMap.set(id, buildFileLink(factorDoc.path));
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
const branchMap = new Map<string, string>();
|
||||
await Promise.all(
|
||||
Array.from(branchIds).map(async (id) => {
|
||||
const branch = await this.branchDbService.findById(id);
|
||||
if (branch?.name) {
|
||||
branchMap.set(id, branch.name);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
mapped.parts = parts.map((part: any) => {
|
||||
const nextPart = { ...part };
|
||||
|
||||
if (nextPart.factorLink && Types.ObjectId.isValid(String(nextPart.factorLink))) {
|
||||
const link = factorMap.get(String(nextPart.factorLink));
|
||||
if (link) nextPart.factorLink = link;
|
||||
}
|
||||
|
||||
const daghi = nextPart.daghi;
|
||||
if (daghi && typeof daghi === "object" && !Array.isArray(daghi)) {
|
||||
const branchId = (daghi as any).branchId;
|
||||
const branchName =
|
||||
branchId && Types.ObjectId.isValid(String(branchId))
|
||||
? branchMap.get(String(branchId))
|
||||
: undefined;
|
||||
nextPart.daghi = {
|
||||
...daghi,
|
||||
...(branchName ? { branchName } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
return nextPart;
|
||||
});
|
||||
|
||||
return mapped;
|
||||
};
|
||||
|
||||
return {
|
||||
...evaluation,
|
||||
damageExpertReply: await mapReply(evaluation.damageExpertReply),
|
||||
damageExpertReplyFinal: await mapReply(evaluation.damageExpertReplyFinal),
|
||||
};
|
||||
}
|
||||
|
||||
async submitUserReply(
|
||||
requestId: string,
|
||||
body: UserCommentDto,
|
||||
@@ -2189,6 +2273,7 @@ export class ClaimRequestManagementService {
|
||||
return {
|
||||
message: "Factor uploaded successfully. Awaiting expert validation.",
|
||||
factorId: factorRecord._id,
|
||||
factorLink: buildFileLink(file.path),
|
||||
url: buildFileLink(file.path),
|
||||
};
|
||||
} catch (error) {
|
||||
@@ -5191,6 +5276,8 @@ export class ClaimRequestManagementService {
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const mappedEvaluation = await this.mapEvaluationForClient(claim.evaluation);
|
||||
|
||||
return {
|
||||
claimRequestId: claim._id.toString(),
|
||||
publicId: claim.publicId,
|
||||
@@ -5210,10 +5297,10 @@ export class ClaimRequestManagementService {
|
||||
carAngles,
|
||||
damagedParts,
|
||||
expertResend,
|
||||
evaluation: claim.evaluation
|
||||
evaluation: mappedEvaluation
|
||||
? {
|
||||
damageExpertReply: claim.evaluation.damageExpertReply,
|
||||
damageExpertReplyFinal: claim.evaluation.damageExpertReplyFinal,
|
||||
damageExpertReply: mappedEvaluation.damageExpertReply,
|
||||
damageExpertReplyFinal: mappedEvaluation.damageExpertReplyFinal,
|
||||
}
|
||||
: undefined,
|
||||
...(isExpertViewer
|
||||
|
||||
@@ -274,6 +274,27 @@ export class ClaimRequestManagementV2Controller {
|
||||
return this.claimRequestManagementService.getOuterPartsCatalogV2(carType);
|
||||
}
|
||||
|
||||
@Get("branches/:insuranceId")
|
||||
@ApiOperation({
|
||||
summary: "Get insurer branches (V2)",
|
||||
description:
|
||||
"Returns branch list for a given insurer/client id so frontend can render branch options (name/code/address/city/state) and submit selected branchId in daghi part options.",
|
||||
})
|
||||
@ApiParam({
|
||||
name: "insuranceId",
|
||||
description: "Insurer client id (MongoDB ObjectId)",
|
||||
example: "60d5ec49e7b2f8001c8e4d2a",
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: "List of branches for insurer",
|
||||
})
|
||||
async getInsuranceBranchesV2(@Param("insuranceId") insuranceId: string) {
|
||||
return await this.claimRequestManagementService.retrieveInsuranceBranches(
|
||||
insuranceId,
|
||||
);
|
||||
}
|
||||
|
||||
@Get("car-other-part")
|
||||
@ApiOperation({
|
||||
summary: "Get other (non-body) parts catalog",
|
||||
|
||||
@@ -6408,6 +6408,12 @@ export class RequestManagementService {
|
||||
},
|
||||
});
|
||||
|
||||
if (
|
||||
updatedRequest.type === BlameRequestType.THIRD_PARTY ||
|
||||
updatedRequest.type === BlameRequestType.CAR_BODY
|
||||
) {
|
||||
let targetPhone: string | undefined;
|
||||
|
||||
if (updatedRequest.type === BlameRequestType.THIRD_PARTY) {
|
||||
const guiltyPartyId = updatedRequest.expert?.decision?.guiltyPartyId
|
||||
? String(updatedRequest.expert.decision.guiltyPartyId)
|
||||
@@ -6416,20 +6422,26 @@ export class RequestManagementService {
|
||||
const damagedParty = updatedRequest.parties?.find(
|
||||
(p) => p.person?.userId && String(p.person.userId) !== guiltyPartyId,
|
||||
);
|
||||
const phone = damagedParty?.person?.phoneNumber?.trim();
|
||||
if (phone) {
|
||||
targetPhone = damagedParty?.person?.phoneNumber?.trim();
|
||||
}
|
||||
} else {
|
||||
// CAR_BODY has a single owner/damaged party: notify that user too.
|
||||
const ownerParty = updatedRequest.parties?.[partyIndex] ?? updatedRequest.parties?.[0];
|
||||
targetPhone = ownerParty?.person?.phoneNumber?.trim();
|
||||
}
|
||||
|
||||
if (targetPhone) {
|
||||
const publicId = String(updatedRequest.publicId);
|
||||
const link = this.smsOrchestrationService.buildClaimLink(requestId);
|
||||
await this.smsOrchestrationService.sendThirdPartyDamagedPartyClaimLinkNotice(
|
||||
{
|
||||
receptor: phone,
|
||||
receptor: targetPhone,
|
||||
publicId,
|
||||
link,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
finalStatus = CaseStatus.STOPPED;
|
||||
message =
|
||||
|
||||
Reference in New Issue
Block a user