Fixed clientId of claim error

This commit is contained in:
SepehrYahyaee
2026-06-03 12:30:42 +03:30
parent 0b47e8789b
commit bd5a33e2ba

View File

@@ -3984,16 +3984,28 @@ export class ClaimRequestManagementService {
owner: { owner: {
userId: new Types.ObjectId(currentUserId), userId: new Types.ObjectId(currentUserId),
userRole: currentUserParty.role as any, userRole: currentUserParty.role as any,
...(currentUserParty.person?.clientId fullName: currentUserParty.person?.fullName,
? { userClientKey: currentUserParty.person?.clientId
clientId: new Types.ObjectId( ? String(currentUserParty.person.clientId)
String(blameRequest?.expert?.decision?.guiltyPartyId) === : undefined,
String(blameRequest?.parties[0]?.person?.userId) // clientId must be the GUILTY party's clientId — their insurer pays the claim
? blameRequest?.parties[0]?.person?.clientId ...(() => {
: blameRequest?.parties[1]?.person?.clientId, if (isCarBody) {
), // CAR_BODY has no guilty party — use the first party's own clientId
} const firstParty = parties.find((p) => p.role === "FIRST");
: {}), const cid = firstParty?.person?.clientId;
return cid ? { clientId: new Types.ObjectId(String(cid)) } : {};
}
const guiltyPartyId = String(
blameRequest?.expert?.decision?.guiltyPartyId ?? "",
);
const guiltyParty = parties.find(
(p) => String(p.person?.userId) === guiltyPartyId,
);
const cid = guiltyParty?.person?.clientId;
return cid ? { clientId: new Types.ObjectId(String(cid)) } : {};
})(),
}, },
history: [ history: [
{ {