forked from Yara724/api
Retain inquiry audit context on failure
This commit is contained in:
@@ -336,6 +336,18 @@ export class RequestManagementService {
|
||||
}
|
||||
}
|
||||
|
||||
private recordInquiryParticipantContext(
|
||||
req: any,
|
||||
role: PartyRole,
|
||||
submission: NormalizedInquirySubmission<Record<string, any>>,
|
||||
): void {
|
||||
this.recordPartyCaseInquiryStatus(req, "participantContext", role, true, {
|
||||
participants: submission.participants.participants,
|
||||
participantRoles: submission.participants.roles,
|
||||
vehicle: submission.vehicle,
|
||||
});
|
||||
}
|
||||
|
||||
private async getThirdPartyPlateInquiry(
|
||||
submission: NormalizedInquirySubmission<Record<string, any>>,
|
||||
options?: Record<string, any>,
|
||||
@@ -587,7 +599,10 @@ export class RequestManagementService {
|
||||
if (!req?._id || !req.inquiries) return;
|
||||
try {
|
||||
await this.blameRequestDbService.findByIdAndUpdate(req._id, {
|
||||
$set: { inquiries: req.inquiries },
|
||||
$set: {
|
||||
inquiries: req.inquiries,
|
||||
...(Array.isArray(req.parties) ? { parties: req.parties } : {}),
|
||||
},
|
||||
});
|
||||
} catch (error: any) {
|
||||
this.logger.error(
|
||||
@@ -1791,9 +1806,7 @@ export class RequestManagementService {
|
||||
{},
|
||||
err,
|
||||
);
|
||||
await this.blameRequestDbService.findByIdAndUpdate(req._id, {
|
||||
$set: { inquiries: req.inquiries },
|
||||
});
|
||||
await this.persistBlameInquiryAudit(req);
|
||||
throw new HttpException("Inquiry failed", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@@ -1808,9 +1821,7 @@ export class RequestManagementService {
|
||||
raw: inquiryRaw,
|
||||
mapped: inquiryMapped,
|
||||
});
|
||||
await this.blameRequestDbService.findByIdAndUpdate(req._id, {
|
||||
$set: { inquiries: req.inquiries },
|
||||
});
|
||||
await this.persistBlameInquiryAudit(req);
|
||||
throw new HttpException(
|
||||
inquiryMapped.Error.Message || "Inquiry returned error",
|
||||
HttpStatus.BAD_REQUEST,
|
||||
@@ -1932,9 +1943,7 @@ export class RequestManagementService {
|
||||
{},
|
||||
err,
|
||||
);
|
||||
await this.blameRequestDbService.findByIdAndUpdate(req._id, {
|
||||
$set: { inquiries: req.inquiries },
|
||||
});
|
||||
await this.persistBlameInquiryAudit(req);
|
||||
this.throwCarBodyInquiryFailure(err);
|
||||
}
|
||||
|
||||
@@ -2189,9 +2198,7 @@ export class RequestManagementService {
|
||||
{},
|
||||
err,
|
||||
);
|
||||
await this.blameRequestDbService.findByIdAndUpdate(req._id, {
|
||||
$set: { inquiries: req.inquiries },
|
||||
});
|
||||
await this.persistBlameInquiryAudit(req);
|
||||
throw new HttpException("VIN inquiry failed", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@@ -2204,9 +2211,7 @@ export class RequestManagementService {
|
||||
raw: inquiryRaw,
|
||||
mapped: inquiryMapped,
|
||||
});
|
||||
await this.blameRequestDbService.findByIdAndUpdate(req._id, {
|
||||
$set: { inquiries: req.inquiries },
|
||||
});
|
||||
await this.persistBlameInquiryAudit(req);
|
||||
throw new HttpException(
|
||||
inquiryMapped.Error.Message || "VIN inquiry returned error",
|
||||
HttpStatus.BAD_REQUEST,
|
||||
@@ -2363,9 +2368,7 @@ export class RequestManagementService {
|
||||
{},
|
||||
err,
|
||||
);
|
||||
await this.blameRequestDbService.findByIdAndUpdate(req._id, {
|
||||
$set: { inquiries: req.inquiries },
|
||||
});
|
||||
await this.persistBlameInquiryAudit(req);
|
||||
this.throwCarBodyInquiryFailure(err);
|
||||
}
|
||||
}
|
||||
@@ -6832,6 +6835,18 @@ export class RequestManagementService {
|
||||
formData.firstPartyPlate,
|
||||
PartyRole.FIRST,
|
||||
);
|
||||
this.recordInquiryParticipantContext(
|
||||
req,
|
||||
PartyRole.FIRST,
|
||||
inquirySubmission,
|
||||
);
|
||||
const existingFirstPartyIndex = this.getPartyIndex(req, PartyRole.FIRST);
|
||||
if (existingFirstPartyIndex !== -1) {
|
||||
this.applyInquiryParticipantsToParty(
|
||||
req.parties[existingFirstPartyIndex],
|
||||
inquirySubmission,
|
||||
);
|
||||
}
|
||||
const firstPartyPlate = inquirySubmission.dto;
|
||||
let sandHubReport: any;
|
||||
try {
|
||||
@@ -7130,6 +7145,14 @@ export class RequestManagementService {
|
||||
plateDto,
|
||||
role,
|
||||
);
|
||||
this.recordInquiryParticipantContext(req, role, inquirySubmission);
|
||||
const existingPartyIndex = this.getPartyIndex(req, role);
|
||||
if (existingPartyIndex !== -1) {
|
||||
this.applyInquiryParticipantsToParty(
|
||||
req.parties[existingPartyIndex],
|
||||
inquirySubmission,
|
||||
);
|
||||
}
|
||||
plateDto = inquirySubmission.dto;
|
||||
const policyholderUnknown =
|
||||
inquirySubmission.thirdPartyPolicyholder.unknown === true;
|
||||
@@ -9667,6 +9690,7 @@ export class RequestManagementService {
|
||||
}
|
||||
|
||||
if (inquiryMapped?.Error) {
|
||||
await this.persistBlameInquiryAudit(req);
|
||||
throw new BadRequestException(
|
||||
inquiryMapped.Error.Message ||
|
||||
`${roleLabel} party plate inquiry returned an error`,
|
||||
@@ -9676,6 +9700,7 @@ export class RequestManagementService {
|
||||
const clientName = inquiryMapped?.CompanyName;
|
||||
const companyCode = inquiryMapped?.CompanyCode;
|
||||
if (!clientName && !policyholderUnknown) {
|
||||
await this.persistBlameInquiryAudit(req);
|
||||
throw new BadRequestException(
|
||||
`CompanyName missing from ${roleLabel} party inquiry response`,
|
||||
);
|
||||
@@ -9687,6 +9712,7 @@ export class RequestManagementService {
|
||||
)
|
||||
: null;
|
||||
if (clientName && !client) {
|
||||
await this.persistBlameInquiryAudit(req);
|
||||
throw new BadRequestException(
|
||||
`CompanyCode missing or invalid in ${roleLabel} party inquiry response`,
|
||||
);
|
||||
@@ -10517,6 +10543,7 @@ export class RequestManagementService {
|
||||
}
|
||||
|
||||
if (inquiryMapped?.Error) {
|
||||
await this.persistBlameInquiryAudit(req);
|
||||
throw new BadRequestException(
|
||||
inquiryMapped.Error.Message ||
|
||||
`${roleLabel} party VIN inquiry returned an error`,
|
||||
@@ -10526,6 +10553,7 @@ export class RequestManagementService {
|
||||
const clientName = inquiryMapped?.CompanyName;
|
||||
const companyCode = inquiryMapped?.CompanyCode;
|
||||
if (!clientName) {
|
||||
await this.persistBlameInquiryAudit(req);
|
||||
throw new BadRequestException(
|
||||
`CompanyName missing from ${roleLabel} party VIN inquiry response`,
|
||||
);
|
||||
@@ -10535,6 +10563,7 @@ export class RequestManagementService {
|
||||
clientName,
|
||||
);
|
||||
if (!client) {
|
||||
await this.persistBlameInquiryAudit(req);
|
||||
throw new BadRequestException(
|
||||
`CompanyCode missing or invalid in ${roleLabel} party VIN inquiry response`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user