From c8ccd943f2e85c745b61d583f4b6dc506bc4bf06 Mon Sep 17 00:00:00 2001 From: SepehrYahyaee <7heycallmegray@gmail.com> Date: Mon, 3 Aug 2026 12:12:47 +0330 Subject: [PATCH] Fixed v6 statuses and steps --- .../request-management.service.ts | 98 +++++++++++++++---- 1 file changed, 78 insertions(+), 20 deletions(-) diff --git a/src/request-management/request-management.service.ts b/src/request-management/request-management.service.ts index c139497..ec992c7 100644 --- a/src/request-management/request-management.service.ts +++ b/src/request-management/request-management.service.ts @@ -272,6 +272,31 @@ export class RequestManagementService { req: any, submittedStepKey: WorkflowStep, ) { + // V6 call-center initiated THIRD_PARTY: skip FIRST_INITIAL_FORM because the + // call-center agent already ran the inquiry during run-inquiry. + // After FIRST_VIDEO, jump straight to FIRST_LOCATION. + if ( + req.callCenterInitiated && + req.type === BlameRequestType.THIRD_PARTY && + submittedStepKey === WorkflowStep.FIRST_VIDEO + ) { + const completed = Array.isArray(req.workflow.completedSteps) + ? req.workflow.completedSteps + : []; + if (!completed.includes(submittedStepKey)) completed.push(submittedStepKey); + // Also mark FIRST_INITIAL_FORM as completed so the step chain is consistent + if (!completed.includes(WorkflowStep.FIRST_INITIAL_FORM)) { + completed.push(WorkflowStep.FIRST_INITIAL_FORM); + } + req.workflow.completedSteps = completed; + req.workflow.currentStep = WorkflowStep.FIRST_LOCATION; + req.workflow.nextStep = WorkflowStep.FIRST_VOICE; + this.logger.debug( + "[WORKFLOW] V6 call-center: skipped FIRST_INITIAL_FORM after FIRST_VIDEO, advanced to FIRST_LOCATION", + ); + return; + } + // CAR_BODY: after first-party description, move to signature step. if ( req.type === BlameRequestType.CAR_BODY && @@ -326,9 +351,15 @@ export class RequestManagementService { req.creationMethod === CreationMethod.IN_PERSON && (req.expertInitiated || req.registrarInitiated); + // V6 call-center THIRD_PARTY: guilt is pre-decided (first party is always guilty), + // so skip the WAITING_FOR_GUILT_DECISION waiting state just like IN_PERSON. + const isCallCenterThirdParty = + req.type === BlameRequestType.THIRD_PARTY && + !!req.callCenterInitiated; + const resolveStep = (step: WorkflowStep | undefined): WorkflowStep | undefined => { if ( - isInPersonThirdParty && + (isInPersonThirdParty || isCallCenterThirdParty) && step === WorkflowStep.WAITING_FOR_GUILT_DECISION ) { return WorkflowStep.WAITING_FOR_SIGNATURES; @@ -1045,26 +1076,38 @@ export class RequestManagementService { if (!completed.includes(step3Key)) { completed.push(step3Key); } - req.workflow.completedSteps = completed; - const nextStepKey = step3.nextPossibleSteps?.[0] as - | WorkflowStep - | undefined; - if (!nextStepKey) { - throw new InternalServerErrorException( - "Workflow stepNumber=3 has no nextPossibleSteps configured", - ); - } - const nextStepDoc = await this.getWorkflowStep({ stepKey: nextStepKey }); - const afterNext = nextStepDoc.nextPossibleSteps?.[0]; - if (!afterNext) { - throw new InternalServerErrorException( - `Workflow step ${nextStepKey} has no nextPossibleSteps configured`, - ); - } + // V6 call-center initiated THIRD_PARTY: inquiry already done by agent — skip + // FIRST_INITIAL_FORM and go straight to FIRST_LOCATION. + if (req.callCenterInitiated && req.type === BlameRequestType.THIRD_PARTY) { + if (!completed.includes(WorkflowStep.FIRST_INITIAL_FORM)) { + completed.push(WorkflowStep.FIRST_INITIAL_FORM); + } + req.workflow.completedSteps = completed; + req.workflow.currentStep = WorkflowStep.FIRST_LOCATION; + req.workflow.nextStep = WorkflowStep.FIRST_VOICE; + } else { + req.workflow.completedSteps = completed; - req.workflow.currentStep = nextStepKey; - req.workflow.nextStep = afterNext as WorkflowStep; + const nextStepKey = step3.nextPossibleSteps?.[0] as + | WorkflowStep + | undefined; + if (!nextStepKey) { + throw new InternalServerErrorException( + "Workflow stepNumber=3 has no nextPossibleSteps configured", + ); + } + const nextStepDoc = await this.getWorkflowStep({ stepKey: nextStepKey }); + const afterNext = nextStepDoc.nextPossibleSteps?.[0]; + if (!afterNext) { + throw new InternalServerErrorException( + `Workflow step ${nextStepKey} has no nextPossibleSteps configured`, + ); + } + + req.workflow.currentStep = nextStepKey; + req.workflow.nextStep = afterNext as WorkflowStep; + } // History if (!Array.isArray(req.history)) req.history = []; @@ -2139,6 +2182,19 @@ export class RequestManagementService { req.type === BlameRequestType.THIRD_PARTY; let closedByMutualAgreement = false; + // V6 call-center initiated THIRD_PARTY: first party is always the guilty party. + // If blameStatus is still UNKNOWN here (pre-fix file or race condition), force it to AGREED now. + if (isSecondThirdParty && req.callCenterInitiated && req.blameStatus !== BlameStatus.AGREED) { + const firstIdx = this.getPartyIndex(req, PartyRole.FIRST); + if (firstIdx !== -1) { + if (!req.parties[firstIdx].statement) req.parties[firstIdx].statement = {} as any; + req.parties[firstIdx].statement.admitsGuilt = true; + req.parties[firstIdx].statement.claimsDamage = false; + req.parties[firstIdx].statement.acceptsExpertOpinion = false; + } + req.blameStatus = BlameStatus.AGREED; + } + // THIRD_PARTY + AGREED: guilt/damage already implied by first-party confession — no field expert needed. if (isSecondThirdParty && req.blameStatus === BlameStatus.AGREED) { const built = buildMutualAgreementExpertDecision( @@ -10743,7 +10799,9 @@ export class RequestManagementService { const firstParty = req.parties[firstIdx]; await this.runPartyInquiriesV3Internal(req, dto, PartyRole.FIRST, firstParty); - this.markPartyInquiriesCompleteOnBlame(req, PartyRole.FIRST, agent); + // Do NOT call markPartyInquiriesCompleteOnBlame here: that helper is for V3/V4/V5 + // FileMaker flows and would advance the workflow to FIRST_LOCATION prematurely. + // In V6 the workflow must stay at CREATED until send-link advances it to FIRST_VIDEO. if (!Array.isArray((req as any).history)) (req as any).history = []; (req as any).history.push({ type: "CALL_CENTER_INQUIRY_COMPLETED",