forked from Yara724/api
Route inquiries by participant role
This commit is contained in:
@@ -78,6 +78,7 @@ import {
|
||||
blameDamagedPartyMatchesUser,
|
||||
resolveClaimOwnerFieldsFromBlame,
|
||||
resolveClaimOwnerParty,
|
||||
resolveDamagedPartyRow,
|
||||
resolveDamagedPartyUserId,
|
||||
} from "src/helpers/blame-damaged-party";
|
||||
import { claimCaseInitiatedByFieldExpert } from "src/helpers/tenant-scope";
|
||||
@@ -115,6 +116,8 @@ import { BranchDbService } from "src/client/entities/db-service/branch.db.servic
|
||||
import { CreationMethod } from "src/request-management/entities/schema/request-management.schema";
|
||||
import { RoleEnum } from "src/Types&Enums/role.enum";
|
||||
import { PartyRole } from "src/request-management/entities/schema/partyRole.enum";
|
||||
import { InquiryParticipantRole } from "src/common/dto/inquiry-participants.dto";
|
||||
import { participantForStoredPartyRole } from "src/request-management/inquiry-participant-resolver";
|
||||
import { UserRatingDto } from "./dto/user-rating.dto";
|
||||
import {
|
||||
canFinalizeExpertResend,
|
||||
@@ -622,6 +625,20 @@ export class ClaimRequestManagementService {
|
||||
return this.parsePlateFromCompactString(compactPlateId);
|
||||
}
|
||||
|
||||
private resolveVehicleOwnerNationalCodeForClaim(
|
||||
blameRequest: any,
|
||||
): string | undefined {
|
||||
const damagedParty = resolveDamagedPartyRow(blameRequest as any);
|
||||
const owner = damagedParty
|
||||
? participantForStoredPartyRole(
|
||||
damagedParty as any,
|
||||
InquiryParticipantRole.VEHICLE_OWNER,
|
||||
)
|
||||
: undefined;
|
||||
const nationalCode = String(owner?.nationalCode ?? "").trim();
|
||||
return nationalCode || undefined;
|
||||
}
|
||||
|
||||
private delay(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
@@ -9195,7 +9212,7 @@ export class ClaimRequestManagementService {
|
||||
|
||||
const shebaDigits = shebaInput.replace(/^IR/i, "");
|
||||
const shebaNumber = `IR${shebaDigits}`;
|
||||
const nationalCode = String(
|
||||
const submittedNationalCode = String(
|
||||
((body as any).nationalCodeOfOwner ??
|
||||
(body as any).nationalCodeOfInsurer ??
|
||||
"") as string,
|
||||
@@ -9205,17 +9222,28 @@ export class ClaimRequestManagementService {
|
||||
"shebaNumber is required and must be valid (IR + 24 digits or only 24 digits)",
|
||||
);
|
||||
}
|
||||
if (!/^[0-9]{10}$/.test(nationalCode)) {
|
||||
throw new BadRequestException(
|
||||
"nationalCodeOfOwner is required and must be exactly 10 digits",
|
||||
);
|
||||
}
|
||||
|
||||
const blameRequest = claimCase.blameRequestId
|
||||
? await this.blameRequestDbService.findById(
|
||||
claimCase.blameRequestId.toString(),
|
||||
)
|
||||
: null;
|
||||
const storedOwnerNationalCode =
|
||||
this.resolveVehicleOwnerNationalCodeForClaim(blameRequest);
|
||||
if (
|
||||
storedOwnerNationalCode &&
|
||||
submittedNationalCode &&
|
||||
submittedNationalCode !== storedOwnerNationalCode
|
||||
) {
|
||||
throw new BadRequestException(
|
||||
"Submitted national code does not match the vehicle owner saved on the blame case.",
|
||||
);
|
||||
}
|
||||
const nationalCode = storedOwnerNationalCode ?? submittedNationalCode;
|
||||
if (!/^[0-9]{10}$/.test(nationalCode)) {
|
||||
throw new BadRequestException(
|
||||
"Vehicle owner national code is unavailable; a 10-digit nationalCodeOfOwner is required only for legacy claims.",
|
||||
);
|
||||
}
|
||||
const ownershipPlate = this.resolveOwnershipPlateForClaim(
|
||||
claimCase,
|
||||
blameRequest,
|
||||
|
||||
@@ -56,20 +56,21 @@ export class SelectOtherPartsV2Dto {
|
||||
@IsString()
|
||||
shebaNumber?: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'National code of insurer/owner - 10 digits',
|
||||
@ApiPropertyOptional({
|
||||
description:
|
||||
'Legacy fallback for claims created before participant roles were stored. New claims derive the vehicle owner national code from the linked blame case.',
|
||||
example: '1234567890',
|
||||
pattern: '^[0-9]{10}$',
|
||||
minLength: 10,
|
||||
maxLength: 10,
|
||||
})
|
||||
@IsNotEmpty({ message: 'nationalCodeOfInsurer is required' })
|
||||
@IsOptional()
|
||||
@IsString({ message: 'National code must be a string' })
|
||||
@Length(10, 10, { message: 'National code must be exactly 10 digits' })
|
||||
@Matches(/^[0-9]{10}$/, {
|
||||
message: 'National code must contain exactly 10 digits',
|
||||
})
|
||||
nationalCodeOfInsurer: string;
|
||||
nationalCodeOfInsurer?: string;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: 'Legacy alias for backward compatibility',
|
||||
|
||||
Reference in New Issue
Block a user