From 5812637a1e6decfc26e752feaba413d6c0c6c974 Mon Sep 17 00:00:00 2001 From: SepehrYahyaee <7heycallmegray@gmail.com> Date: Sun, 13 Sep 2026 12:55:55 +0330 Subject: [PATCH] Mark rejected inquiry results as failed --- .../request-management.service.ts | 108 ++++++++++++++++-- 1 file changed, 96 insertions(+), 12 deletions(-) diff --git a/src/request-management/request-management.service.ts b/src/request-management/request-management.service.ts index 085ac8c..8035063 100644 --- a/src/request-management/request-management.service.ts +++ b/src/request-management/request-management.service.ts @@ -9690,20 +9690,50 @@ export class RequestManagementService { } if (inquiryMapped?.Error) { - await this.persistBlameInquiryAudit(req); - throw new BadRequestException( + const error = new BadRequestException( inquiryMapped.Error.Message || `${roleLabel} party plate inquiry returned an error`, ); + this.recordPartyCaseInquiryStatus( + req, + "thirdParty", + partyRole, + false, + { + source: inquirySource, + plateKind: inquiryPlateKind, + attempts: inquiryAttempts, + raw: inquiryRaw, + mapped: inquiryMapped, + }, + error, + ); + await this.persistBlameInquiryAudit(req); + throw error; } const clientName = inquiryMapped?.CompanyName; const companyCode = inquiryMapped?.CompanyCode; if (!clientName && !policyholderUnknown) { - await this.persistBlameInquiryAudit(req); - throw new BadRequestException( + const error = new BadRequestException( `CompanyName missing from ${roleLabel} party inquiry response`, ); + this.recordPartyCaseInquiryStatus( + req, + "thirdParty", + partyRole, + false, + { + source: inquirySource, + plateKind: inquiryPlateKind, + attempts: inquiryAttempts, + raw: inquiryRaw, + mapped: inquiryMapped, + }, + error, + ); + await this.persistBlameInquiryAudit(req); + throw error; } const client = clientName ? await this.clientService.findOrCreateClientByCompanyCode( @@ -9712,10 +9742,25 @@ export class RequestManagementService { ) : null; if (clientName && !client) { - await this.persistBlameInquiryAudit(req); - throw new BadRequestException( + const error = new BadRequestException( `CompanyCode missing or invalid in ${roleLabel} party inquiry response`, ); + this.recordPartyCaseInquiryStatus( + req, + "thirdParty", + partyRole, + false, + { + source: inquirySource, + plateKind: inquiryPlateKind, + attempts: inquiryAttempts, + raw: inquiryRaw, + mapped: inquiryMapped, + }, + error, + ); + await this.persistBlameInquiryAudit(req); + throw error; } const resolvedClientId = (client as any)?._id ?? (client as any)?._doc?._id; clientId = resolvedClientId ? String(resolvedClientId) : undefined; @@ -10543,30 +10588,69 @@ export class RequestManagementService { } if (inquiryMapped?.Error) { - await this.persistBlameInquiryAudit(req); - throw new BadRequestException( + const error = new BadRequestException( inquiryMapped.Error.Message || `${roleLabel} party VIN inquiry returned an error`, ); + this.recordPartyCaseInquiryStatus( + req, + "thirdParty", + partyRole, + false, + { + source: "ESG_VIN_INQUIRY", + raw: inquiryRaw, + mapped: inquiryMapped, + }, + error, + ); + await this.persistBlameInquiryAudit(req); + throw error; } const clientName = inquiryMapped?.CompanyName; const companyCode = inquiryMapped?.CompanyCode; if (!clientName) { - await this.persistBlameInquiryAudit(req); - throw new BadRequestException( + const error = new BadRequestException( `CompanyName missing from ${roleLabel} party VIN inquiry response`, ); + this.recordPartyCaseInquiryStatus( + req, + "thirdParty", + partyRole, + false, + { + source: "ESG_VIN_INQUIRY", + raw: inquiryRaw, + mapped: inquiryMapped, + }, + error, + ); + await this.persistBlameInquiryAudit(req); + throw error; } const client = await this.clientService.findOrCreateClientByCompanyCode( companyCode, clientName, ); if (!client) { - await this.persistBlameInquiryAudit(req); - throw new BadRequestException( + const error = new BadRequestException( `CompanyCode missing or invalid in ${roleLabel} party VIN inquiry response`, ); + this.recordPartyCaseInquiryStatus( + req, + "thirdParty", + partyRole, + false, + { + source: "ESG_VIN_INQUIRY", + raw: inquiryRaw, + mapped: inquiryMapped, + }, + error, + ); + await this.persistBlameInquiryAudit(req); + throw error; } const resolvedClientId = (client as any)?._id ?? (client as any)?._doc?._id; clientId = resolvedClientId ? String(resolvedClientId) : undefined;