From 2cc96f61326e2cdbed42e8c5cdc3d3a87968c338 Mon Sep 17 00:00:00 2001 From: SepehrYahyaee <7heycallmegray@gmail.com> Date: Wed, 22 Jul 2026 14:52:51 +0330 Subject: [PATCH] Fixed v2 flow --- ...xpert-initiated-blame.mirror.controller.ts | 11 +++++---- .../request-management.service.ts | 23 +++++++++++++++---- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/request-management/expert-initiated-blame.mirror.controller.ts b/src/request-management/expert-initiated-blame.mirror.controller.ts index 0bdbc23..c1e70b2 100644 --- a/src/request-management/expert-initiated-blame.mirror.controller.ts +++ b/src/request-management/expert-initiated-blame.mirror.controller.ts @@ -34,6 +34,7 @@ import { LocationDto, } from "./dto/create-request-management.dto"; import { CreateExpertInitiatedFileDto } from "./dto/expert-initiated.dto"; +import { CreationMethod } from "./entities/schema/request-management.schema"; import { SendPartyOtpsDto } from "./dto/send-party-otps.dto"; import { VerifyPartyOtpsDto } from "./dto/verify-party-otps.dto"; import { SendPartyOtpDto, VerifyPartyOtpDto } from "./dto/party-otp.dto"; @@ -75,17 +76,17 @@ export class ExpertInitiatedBlameMirrorController { @ApiOperation({ summary: "[Expert mirror] Create expert-initiated blame file", description: - "Use creationMethod=IN_PERSON for the on-site flow. Creates a BlameRequest owned by the parties but filled by the expert.", + "Creates an IN_PERSON blame file filled by the expert on behalf of both parties. creationMethod is always forced to IN_PERSON regardless of what is sent.", }) @ApiBody({ type: CreateExpertInitiatedFileDto }) async create( @CurrentUser() expert: any, @Body() dto: CreateExpertInitiatedFileDto, ) { - return this.requestManagementService.createExpertInitiatedBlameV2( - expert, - dto, - ); + return this.requestManagementService.createExpertInitiatedBlameV2(expert, { + ...dto, + creationMethod: CreationMethod.IN_PERSON, + }); } @Post("send-link/:requestId") diff --git a/src/request-management/request-management.service.ts b/src/request-management/request-management.service.ts index 0ab3e95..95c04c1 100644 --- a/src/request-management/request-management.service.ts +++ b/src/request-management/request-management.service.ts @@ -6637,11 +6637,11 @@ export class RequestManagementService { ); } await this.verifyExpertAccessForBlameV2(req, expert); - // if (req.status !== CaseStatus.WAITING_FOR_SIGNATURES) { - // throw new BadRequestException( - // "Request is not waiting for signatures. Current status: " + req.status, - // ); - // } + if (req.status !== CaseStatus.WAITING_FOR_SIGNATURES) { + throw new BadRequestException( + "Request is not waiting for signatures. Current status: " + req.status, + ); + } const partyIndex = this.getPartyIndex(req, partyRole); if (partyIndex === -1) { throw new BadRequestException( @@ -6753,6 +6753,19 @@ export class RequestManagementService { ); } await this.verifyExpertAccessForBlameV2(req, expert); + // In the V2 IN_PERSON mirror flow guilt is resolved automatically during + // addDescriptionV2 — accident-fields must only be called once the file has + // reached WAITING_FOR_SIGNATURES (both parties' narrative steps are done). + // Calling it earlier would overwrite the workflow and skip the sign step. + if ( + req.creationMethod === CreationMethod.IN_PERSON && + req.status !== CaseStatus.WAITING_FOR_SIGNATURES && + req.status !== CaseStatus.COMPLETED + ) { + throw new BadRequestException( + `accident-fields can only be submitted after both parties have completed their narrative steps (current status: ${req.status}). Make sure both parties have gone through location, voice, and description before calling this endpoint.`, + ); + } if (!req.expert) req.expert = {} as any; if (!req.expert.decision) req.expert.decision = {} as any;