diff --git a/src/claim-request-management/claim-request-management.service.ts b/src/claim-request-management/claim-request-management.service.ts index 11e3a12..6eb088e 100644 --- a/src/claim-request-management/claim-request-management.service.ts +++ b/src/claim-request-management/claim-request-management.service.ts @@ -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: [ {