forked from Yara724/api
fixed many bugs and step issues
This commit is contained in:
@@ -669,7 +669,7 @@ export class ClaimRequestManagementService {
|
||||
"damage.selectedParts": selectedParts,
|
||||
status: ClaimCaseStatus.SELECTING_OTHER_PARTS,
|
||||
"workflow.currentStep": ClaimWorkflowStep.SELECT_OTHER_PARTS,
|
||||
"workflow.nextStep": ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS,
|
||||
"workflow.nextStep": ClaimWorkflowStep.CAPTURE_PART_DAMAGES,
|
||||
$push: {
|
||||
"workflow.completedSteps": ClaimWorkflowStep.SELECT_OUTER_PARTS,
|
||||
history: {
|
||||
@@ -759,9 +759,9 @@ export class ClaimRequestManagementService {
|
||||
otherPartsArr.length > 0 ? otherPartsArr : [],
|
||||
}
|
||||
: {}),
|
||||
status: ClaimCaseStatus.UPLOADING_REQUIRED_DOCUMENTS,
|
||||
"workflow.currentStep": ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS,
|
||||
"workflow.nextStep": ClaimWorkflowStep.CAPTURE_PART_DAMAGES,
|
||||
status: ClaimCaseStatus.CAPTURING_PART_DAMAGES,
|
||||
"workflow.currentStep": ClaimWorkflowStep.CAPTURE_PART_DAMAGES,
|
||||
"workflow.nextStep": ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS,
|
||||
$push: {
|
||||
"workflow.completedSteps": ClaimWorkflowStep.SELECT_OTHER_PARTS,
|
||||
history: {
|
||||
@@ -3184,6 +3184,13 @@ export class ClaimRequestManagementService {
|
||||
owner: {
|
||||
userId: new Types.ObjectId(currentUserId),
|
||||
userRole: currentUserParty.role as any,
|
||||
...(currentUserParty.person?.clientId
|
||||
? {
|
||||
clientId: new Types.ObjectId(
|
||||
currentUserParty.person.clientId as any,
|
||||
),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
history: [
|
||||
{
|
||||
@@ -3305,6 +3312,11 @@ export class ClaimRequestManagementService {
|
||||
owner: {
|
||||
userId: new Types.ObjectId(damagedUserId),
|
||||
userRole: damagedParty?.role as any,
|
||||
...(damagedParty?.person?.clientId
|
||||
? {
|
||||
clientId: new Types.ObjectId(damagedParty.person.clientId as any),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
history: [
|
||||
{
|
||||
@@ -3440,6 +3452,11 @@ export class ClaimRequestManagementService {
|
||||
owner: {
|
||||
userId: new Types.ObjectId(damagedUserId),
|
||||
userRole: damagedParty?.role as any,
|
||||
...(damagedParty?.person?.clientId
|
||||
? {
|
||||
clientId: new Types.ObjectId(damagedParty.person.clientId as any),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
createdByRegistrarId: new Types.ObjectId(registrar.sub),
|
||||
history: [
|
||||
@@ -3550,7 +3567,7 @@ export class ClaimRequestManagementService {
|
||||
'damage.selectedParts': selectedParts,
|
||||
'status': ClaimCaseStatus.SELECTING_OTHER_PARTS,
|
||||
'workflow.currentStep': ClaimWorkflowStep.SELECT_OTHER_PARTS,
|
||||
'workflow.nextStep': ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS,
|
||||
'workflow.nextStep': ClaimWorkflowStep.CAPTURE_PART_DAMAGES,
|
||||
$push: {
|
||||
'workflow.completedSteps': ClaimWorkflowStep.SELECT_OUTER_PARTS,
|
||||
history: {
|
||||
@@ -3586,7 +3603,7 @@ export class ClaimRequestManagementService {
|
||||
publicId: updatedClaim.publicId,
|
||||
selectedParts: selectedParts,
|
||||
currentStep: ClaimWorkflowStep.SELECT_OTHER_PARTS,
|
||||
nextStep: ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS,
|
||||
nextStep: ClaimWorkflowStep.CAPTURE_PART_DAMAGES,
|
||||
message: 'Outer parts selected successfully. Please proceed to select other parts and provide bank information.',
|
||||
};
|
||||
} catch (error) {
|
||||
@@ -3704,9 +3721,9 @@ export class ClaimRequestManagementService {
|
||||
'damage.otherParts': otherParts.length > 0 ? otherParts : undefined,
|
||||
'money.sheba': shebaNumber,
|
||||
'money.nationalCodeOfInsurer': nationalCode,
|
||||
'status': ClaimCaseStatus.UPLOADING_REQUIRED_DOCUMENTS,
|
||||
'status': ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS ,
|
||||
'workflow.currentStep': ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS,
|
||||
'workflow.nextStep': ClaimWorkflowStep.CAPTURE_PART_DAMAGES,
|
||||
'workflow.nextStep': ClaimWorkflowStep.USER_SUBMISSION_COMPLETE,
|
||||
$push: {
|
||||
'workflow.completedSteps': ClaimWorkflowStep.SELECT_OTHER_PARTS,
|
||||
history: {
|
||||
@@ -3785,9 +3802,10 @@ export class ClaimRequestManagementService {
|
||||
otherParts: otherParts,
|
||||
shebaNumber: maskedSheba,
|
||||
nationalCodeOfOwner: maskedNationalCode,
|
||||
currentStep: ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS,
|
||||
nextStep: ClaimWorkflowStep.CAPTURE_PART_DAMAGES,
|
||||
message: 'Other parts and bank information saved successfully. Please proceed to upload required documents.',
|
||||
currentStep: ClaimWorkflowStep.CAPTURE_PART_DAMAGES,
|
||||
nextStep: ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS,
|
||||
message:
|
||||
'Other parts and bank information saved successfully. Please capture car angles and damaged parts, then upload required documents.',
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof HttpException) throw error;
|
||||
@@ -3854,7 +3872,6 @@ export class ClaimRequestManagementService {
|
||||
: null;
|
||||
const isCarBody = blameRequest?.type === BlameRequestType.CAR_BODY;
|
||||
const requiredDocsDefinition = [
|
||||
{ key: 'car_green_card', label_fa: 'کارت سبز خودرو', label_en: 'Car Green Card', category: 'general' },
|
||||
{ key: 'damaged_driving_license_front', label_fa: 'گواهینامه طرف آسیبدیده - جلو', label_en: 'Damaged Party License - Front', category: 'damaged_party' },
|
||||
{ key: 'damaged_driving_license_back', label_fa: 'گواهینامه طرف آسیبدیده - پشت', label_en: 'Damaged Party License - Back', category: 'damaged_party' },
|
||||
{ key: 'damaged_chassis_number', label_fa: 'شماره شاسی', label_en: 'Chassis Number', category: 'damaged_party' },
|
||||
@@ -4036,11 +4053,14 @@ export class ClaimRequestManagementService {
|
||||
const uploadedCount = (currentDocs instanceof Map ? currentDocs.size : Object.keys(currentDocs).length) + 1;
|
||||
const allDocumentsUploaded = uploadedCount >= totalDocsRequired;
|
||||
|
||||
// If all documents uploaded, move to next step
|
||||
// If all documents uploaded, user flow complete (captures were done earlier in v2)
|
||||
if (allDocumentsUploaded) {
|
||||
updateData['status'] = ClaimCaseStatus.CAPTURING_PART_DAMAGES;
|
||||
updateData['workflow.currentStep'] = ClaimWorkflowStep.CAPTURE_PART_DAMAGES;
|
||||
updateData['workflow.nextStep'] = ClaimWorkflowStep.USER_SUBMISSION_COMPLETE;
|
||||
updateData['status'] = ClaimCaseStatus.WAITING_FOR_DAMAGE_EXPERT;
|
||||
updateData['claimStatus'] = ClaimStatus.PENDING;
|
||||
updateData['workflow.currentStep'] =
|
||||
ClaimWorkflowStep.USER_SUBMISSION_COMPLETE;
|
||||
updateData['workflow.nextStep'] =
|
||||
ClaimWorkflowStep.EXPERT_DAMAGE_ASSESSMENT;
|
||||
updateData.$push.history = [
|
||||
updateData.$push.history,
|
||||
{
|
||||
@@ -4056,15 +4076,30 @@ export class ClaimRequestManagementService {
|
||||
description: 'All required documents uploaded',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'STEP_COMPLETED',
|
||||
actor: {
|
||||
actorId: new Types.ObjectId(currentUserId),
|
||||
actorName: claimCase.owner?.fullName || 'User',
|
||||
actorType: 'user',
|
||||
},
|
||||
timestamp: new Date(),
|
||||
metadata: {
|
||||
stepKey: ClaimWorkflowStep.USER_SUBMISSION_COMPLETE,
|
||||
description:
|
||||
'User submission complete. Claim ready for damage expert review.',
|
||||
},
|
||||
},
|
||||
];
|
||||
updateData.$push['workflow.completedSteps'] = ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS;
|
||||
updateData.$push['workflow.completedSteps'] =
|
||||
ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS;
|
||||
}
|
||||
|
||||
await this.claimCaseDbService.findByIdAndUpdate(claimRequestId, updateData);
|
||||
|
||||
const remaining = totalDocsRequired - uploadedCount;
|
||||
const message = allDocumentsUploaded
|
||||
? 'All documents uploaded successfully. Please proceed to capture car angles and damaged parts.'
|
||||
? 'All documents uploaded successfully. Your claim is now ready for damage expert review.'
|
||||
: `Document uploaded successfully. ${remaining} documents remaining.`;
|
||||
|
||||
return {
|
||||
@@ -4072,7 +4107,9 @@ export class ClaimRequestManagementService {
|
||||
documentKey: body.documentKey,
|
||||
fileUrl,
|
||||
allDocumentsUploaded,
|
||||
currentStep: allDocumentsUploaded ? ClaimWorkflowStep.CAPTURE_PART_DAMAGES : ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS,
|
||||
currentStep: allDocumentsUploaded
|
||||
? ClaimWorkflowStep.USER_SUBMISSION_COMPLETE
|
||||
: ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS,
|
||||
message,
|
||||
};
|
||||
} catch (error) {
|
||||
@@ -4169,10 +4206,9 @@ export class ClaimRequestManagementService {
|
||||
|
||||
if (allCapturesComplete) {
|
||||
await this.claimCaseDbService.findByIdAndUpdate(claimRequestId, {
|
||||
status: ClaimCaseStatus.WAITING_FOR_DAMAGE_EXPERT,
|
||||
claimStatus: ClaimStatus.PENDING,
|
||||
'workflow.currentStep': ClaimWorkflowStep.USER_SUBMISSION_COMPLETE,
|
||||
'workflow.nextStep': ClaimWorkflowStep.EXPERT_DAMAGE_ASSESSMENT,
|
||||
status: ClaimCaseStatus.UPLOADING_REQUIRED_DOCUMENTS,
|
||||
'workflow.currentStep': ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS,
|
||||
'workflow.nextStep': ClaimWorkflowStep.USER_SUBMISSION_COMPLETE,
|
||||
$push: {
|
||||
'workflow.completedSteps': ClaimWorkflowStep.CAPTURE_PART_DAMAGES,
|
||||
history: {
|
||||
@@ -4184,8 +4220,9 @@ export class ClaimRequestManagementService {
|
||||
},
|
||||
timestamp: new Date(),
|
||||
metadata: {
|
||||
stepKey: ClaimWorkflowStep.USER_SUBMISSION_COMPLETE,
|
||||
description: 'User submission complete. Claim ready for damage expert review.',
|
||||
stepKey: ClaimWorkflowStep.CAPTURE_PART_DAMAGES,
|
||||
description:
|
||||
'All car angles and damaged parts captured. Please upload required documents.',
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -4194,7 +4231,7 @@ export class ClaimRequestManagementService {
|
||||
|
||||
const remaining = (4 - anglesCaptured) + (selectedParts.length - partsCaptured);
|
||||
const message = allCapturesComplete
|
||||
? 'All captures complete. Your claim is now ready for damage expert review.'
|
||||
? 'All captures complete. Please proceed to upload required documents.'
|
||||
: `${body.captureType === 'angle' ? 'Angle' : 'Part'} captured successfully. ${remaining} captures remaining.`;
|
||||
|
||||
return {
|
||||
@@ -4204,7 +4241,7 @@ export class ClaimRequestManagementService {
|
||||
fileUrl,
|
||||
allCapturesComplete,
|
||||
currentStep: allCapturesComplete
|
||||
? ClaimWorkflowStep.USER_SUBMISSION_COMPLETE
|
||||
? ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS
|
||||
: ClaimWorkflowStep.CAPTURE_PART_DAMAGES,
|
||||
message,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user