forked from Yara724/api
Route inquiries by participant role
This commit is contained in:
@@ -58,6 +58,40 @@ export interface NormalizedInquirySubmission<T extends Record<string, any>> {
|
||||
vehicle?: ResolvedInquiryVehicle;
|
||||
}
|
||||
|
||||
export interface InquirySubjects {
|
||||
thirdPartyPolicyNationalCode: string;
|
||||
carBodyPolicyNationalCode?: string;
|
||||
shebaNationalCode: string;
|
||||
driverNationalCode: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* The single routing seam for external inquiries. Policy checks belong to
|
||||
* their policyholder, Sheba belongs to the vehicle owner, and licence data
|
||||
* belongs to the driver even when those roles resolve to different people.
|
||||
*/
|
||||
export function resolveInquirySubjects(
|
||||
submission: NormalizedInquirySubmission<Record<string, any>>,
|
||||
): InquirySubjects {
|
||||
if (!submission.vehicleOwner) {
|
||||
throw new BadRequestException(
|
||||
"Vehicle owner identity is required for Sheba validation.",
|
||||
);
|
||||
}
|
||||
return {
|
||||
thirdPartyPolicyNationalCode:
|
||||
submission.thirdPartyPolicyholder.nationalCode,
|
||||
...(submission.carBodyPolicyholder
|
||||
? {
|
||||
carBodyPolicyNationalCode:
|
||||
submission.carBodyPolicyholder.nationalCode,
|
||||
}
|
||||
: {}),
|
||||
shebaNationalCode: submission.vehicleOwner.nationalCode,
|
||||
driverNationalCode: submission.driver.nationalCode,
|
||||
};
|
||||
}
|
||||
|
||||
export type ResolvedInquiryVehicle = InquiryVehicleInputDto & {
|
||||
registrationState: VehicleRegistrationState;
|
||||
};
|
||||
@@ -75,6 +109,24 @@ export function participantForRole(
|
||||
);
|
||||
}
|
||||
|
||||
/** Resolve a participant from the role links persisted on a blame party. */
|
||||
export function participantForStoredPartyRole(
|
||||
party: {
|
||||
participants?: Array<Record<string, any>>;
|
||||
participantRoles?: Partial<InquiryParticipantRoleAssignments>;
|
||||
},
|
||||
role: InquiryParticipantRole,
|
||||
): Record<string, any> | undefined {
|
||||
const roleField = ROLE_FIELDS[
|
||||
role
|
||||
] as keyof InquiryParticipantRoleAssignments;
|
||||
const participantId = party.participantRoles?.[roleField];
|
||||
if (!participantId || !Array.isArray(party.participants)) return undefined;
|
||||
return party.participants.find(
|
||||
(participant) => participant?.participantId === participantId,
|
||||
);
|
||||
}
|
||||
|
||||
const ROLE_FIELDS: Record<
|
||||
InquiryParticipantRole,
|
||||
keyof InquiryParticipantFieldsDto
|
||||
|
||||
Reference in New Issue
Block a user