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: {
userId: new Types.ObjectId(currentUserId),
userRole: currentUserParty.role as any,
...(currentUserParty.person?.clientId
? {
clientId: new Types.ObjectId(
String(blameRequest?.expert?.decision?.guiltyPartyId) ===
String(blameRequest?.parties[0]?.person?.userId)
? blameRequest?.parties[0]?.person?.clientId
: blameRequest?.parties[1]?.person?.clientId,
),
}
: {}),
fullName: currentUserParty.person?.fullName,
userClientKey: currentUserParty.person?.clientId
? String(currentUserParty.person.clientId)
: undefined,
// clientId must be the GUILTY party's clientId — their insurer pays the claim
...(() => {
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: [
{