forked from Yara724/api
fix(claims): reuse saved Sheba across claim workflow steps
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
import {
|
||||
normalizeClaimSheba,
|
||||
normalizeClaimNationalCode,
|
||||
savedClaimBankInformation,
|
||||
} from './claim-bank-information';
|
||||
import { UserClaimBranchService, usesUserClaimBranch } from "src/client/user-claim-branch.service";
|
||||
import {
|
||||
hasReviewedTejaratNotifier,
|
||||
@@ -1227,7 +1232,7 @@ export class ClaimRequestManagementService {
|
||||
);
|
||||
}
|
||||
|
||||
const mergedSheba = dto.sheba != null ? dto.sheba : fresh.money?.sheba;
|
||||
const mergedSheba = normalizeClaimSheba(dto.sheba ?? fresh.money?.sheba);
|
||||
const mergedNational =
|
||||
dto.nationalCodeOfInsurer != null
|
||||
? dto.nationalCodeOfInsurer
|
||||
@@ -1236,7 +1241,7 @@ export class ClaimRequestManagementService {
|
||||
if (
|
||||
fresh.money?.sheba &&
|
||||
dto.sheba != null &&
|
||||
dto.sheba !== fresh.money.sheba
|
||||
normalizeClaimSheba(dto.sheba) !== normalizeClaimSheba(fresh.money.sheba)
|
||||
) {
|
||||
throw new ConflictException('Sheba is already set for this claim.');
|
||||
}
|
||||
@@ -1264,7 +1269,7 @@ export class ClaimRequestManagementService {
|
||||
const bankComplete =
|
||||
mergedSheba &&
|
||||
mergedNational &&
|
||||
/^[0-9]{24}$/.test(String(mergedSheba).replace(/\s/g, '')) &&
|
||||
!!normalizeClaimSheba(mergedSheba) &&
|
||||
/^[0-9]{10}$/.test(String(mergedNational).replace(/\s/g, ''));
|
||||
|
||||
if (bankComplete) {
|
||||
@@ -9095,7 +9100,7 @@ export class ClaimRequestManagementService {
|
||||
* - Claim case must exist
|
||||
* - User must be the claim owner (damaged party)
|
||||
* - Current workflow step must be SELECT_OTHER_PARTS (step 3)
|
||||
* - Other parts and bank info must not have been submitted previously
|
||||
* - Saved bank info is reused; only missing fields must be supplied
|
||||
*/
|
||||
async selectOtherPartsV2(
|
||||
claimRequestId: string,
|
||||
@@ -9138,17 +9143,6 @@ export class ClaimRequestManagementService {
|
||||
);
|
||||
}
|
||||
|
||||
// 4. Validate other parts and bank info haven't been submitted yet
|
||||
if (
|
||||
claimCase.money?.sheba &&
|
||||
claimCase.money?.nationalCodeOfInsurer &&
|
||||
claimCase.workflow?.currentStep !== ClaimWorkflowStep.USER_EXPERT_RESEND
|
||||
) {
|
||||
throw new ConflictException(
|
||||
'Bank information has already been submitted for this claim',
|
||||
);
|
||||
}
|
||||
|
||||
// 5. Prepare data
|
||||
// Backward compatibility aliases:
|
||||
// - shebaNumber <- sheba
|
||||
@@ -9168,22 +9162,12 @@ export class ClaimRequestManagementService {
|
||||
otherParts = [];
|
||||
}
|
||||
}
|
||||
const shebaInput = String(
|
||||
((body as any).shebaNumber ?? (body as any).sheba ?? '') as string,
|
||||
).replace(/\s/g, '');
|
||||
|
||||
const shebaDigits = shebaInput.replace(/^IR/i, '');
|
||||
const shebaNumber = `IR${shebaDigits}`;
|
||||
const submittedShebaInput = String(
|
||||
body.shebaNumber ?? body.sheba ?? '',
|
||||
).trim();
|
||||
const submittedNationalCode = String(
|
||||
((body as any).nationalCodeOfOwner ??
|
||||
(body as any).nationalCodeOfInsurer ??
|
||||
'') as string,
|
||||
body.nationalCodeOfOwner ?? body.nationalCodeOfInsurer ?? '',
|
||||
).replace(/\s/g, '');
|
||||
if (!/^[0-9]{24}$/.test(shebaDigits)) {
|
||||
throw new BadRequestException(
|
||||
'shebaNumber is required and must be valid (IR + 24 digits or only 24 digits)',
|
||||
);
|
||||
}
|
||||
const blameRequest = claimCase.blameRequestId
|
||||
? await this.blameRequestDbService.findById(
|
||||
claimCase.blameRequestId.toString(),
|
||||
@@ -9200,10 +9184,34 @@ export class ClaimRequestManagementService {
|
||||
'Submitted national code does not match the vehicle owner saved on the blame case.',
|
||||
);
|
||||
}
|
||||
const nationalCode = storedOwnerNationalCode ?? submittedNationalCode;
|
||||
if (!/^[0-9]{10}$/.test(nationalCode)) {
|
||||
const savedBank = savedClaimBankInformation(
|
||||
claimCase.money,
|
||||
storedOwnerNationalCode,
|
||||
);
|
||||
const shebaNumber = submittedShebaInput
|
||||
? normalizeClaimSheba(submittedShebaInput)
|
||||
: savedBank.sheba;
|
||||
if (!shebaNumber) {
|
||||
throw new BadRequestException(
|
||||
'Vehicle owner national code is unavailable; a 10-digit nationalCodeOfOwner is required only for legacy claims.',
|
||||
'شماره شبا باید شامل IR و ۲۴ رقم یا فقط ۲۴ رقم باشد.',
|
||||
);
|
||||
}
|
||||
if (
|
||||
savedBank.sheba &&
|
||||
submittedShebaInput &&
|
||||
shebaNumber !== savedBank.sheba &&
|
||||
claimCase.workflow?.currentStep !== ClaimWorkflowStep.USER_EXPERT_RESEND
|
||||
) {
|
||||
throw new ConflictException(
|
||||
'شماره شبا قبلاً برای این پرونده ثبت شده است؛ نیازی به ورود مجدد آن نیست.',
|
||||
);
|
||||
}
|
||||
const shebaDigits = shebaNumber.slice(2);
|
||||
const nationalCode =
|
||||
storedOwnerNationalCode ?? (submittedNationalCode || savedBank.nationalCode);
|
||||
if (!normalizeClaimNationalCode(nationalCode)) {
|
||||
throw new BadRequestException(
|
||||
'کد ملی ۱۰ رقمی مالک خودرو برای ثبت اطلاعات حساب الزامی است.',
|
||||
);
|
||||
}
|
||||
const ownershipPlate = this.resolveOwnershipPlateForClaim(
|
||||
@@ -9216,13 +9224,17 @@ export class ClaimRequestManagementService {
|
||||
);
|
||||
}
|
||||
|
||||
let step = claimCase.workflow?.currentStep;
|
||||
|
||||
// External inquiry checks before moving workflow:
|
||||
// 1) ownership check for nationalCode + plate
|
||||
// await this.sandHubService.getCarOwnershipInfo(ownershipPlate, nationalCode);
|
||||
// 2) sheba check for nationalCode + sheba
|
||||
await this.sandHubService.getShebaValidation(nationalCode, shebaNumber);
|
||||
const bankUnchanged =
|
||||
normalizeClaimSheba(claimCase.money?.sheba) === shebaNumber &&
|
||||
normalizeClaimNationalCode(claimCase.money?.nationalCodeOfInsurer) ===
|
||||
nationalCode;
|
||||
if (!bankUnchanged) {
|
||||
await this.sandHubService.getShebaValidation(nationalCode, shebaNumber);
|
||||
}
|
||||
|
||||
const updatePayload: any = {
|
||||
'damage.otherParts': otherParts.length > 0 ? otherParts : undefined,
|
||||
@@ -11613,7 +11625,7 @@ export class ClaimRequestManagementService {
|
||||
? ((
|
||||
await this.blameRequestDbService.find(
|
||||
{ _id: new Types.ObjectId(claim.blameRequestId.toString()) },
|
||||
{ lean: true, select: 'type creationMethod' },
|
||||
{ lean: true, select: 'type creationMethod parties expert' },
|
||||
)
|
||||
)[0] ?? null)
|
||||
: null;
|
||||
@@ -11763,6 +11775,10 @@ export class ClaimRequestManagementService {
|
||||
fullName: claim.owner.fullName,
|
||||
}
|
||||
: undefined;
|
||||
const savedBank = savedClaimBankInformation(
|
||||
claim.money,
|
||||
this.resolveVehicleOwnerNationalCodeForClaim(blameForDetail),
|
||||
);
|
||||
const moneyForUser = claim.money
|
||||
? {
|
||||
sheba: maskSheba(claim.money.sheba),
|
||||
@@ -11801,6 +11817,10 @@ export class ClaimRequestManagementService {
|
||||
selectedParts: selectedNormDetails,
|
||||
otherParts: claim.damage?.otherParts,
|
||||
money: isExpertViewer ? moneyForExpert : moneyForUser,
|
||||
bankInformation: {
|
||||
shebaProvided: savedBank.shebaProvided,
|
||||
ownerNationalCodeProvided: savedBank.ownerNationalCodeProvided,
|
||||
},
|
||||
requiredDocuments:
|
||||
Object.keys(requiredDocumentsStatus).length > 0
|
||||
? requiredDocumentsStatus
|
||||
|
||||
Reference in New Issue
Block a user