From 1b07ca36d4efbe341507aa48809306414be5086f Mon Sep 17 00:00:00 2001 From: Matan Yadaev Date: Mon, 18 Nov 2024 10:58:05 +0200 Subject: [PATCH] fix: correlation id and failed reports --- .../src/domains/business-reports/fetchers.ts | 5 ++++ .../business-report.controller.external.ts | 23 ++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/apps/backoffice-v2/src/domains/business-reports/fetchers.ts b/apps/backoffice-v2/src/domains/business-reports/fetchers.ts index 148cf6b28..371b6d3f0 100644 --- a/apps/backoffice-v2/src/domains/business-reports/fetchers.ts +++ b/apps/backoffice-v2/src/domains/business-reports/fetchers.ts @@ -7,6 +7,7 @@ import { toast } from 'sonner'; import { t } from 'i18next'; import { MERCHANT_REPORT_STATUSES, + MERCHANT_REPORT_STATUSES_MAP, MERCHANT_REPORT_TYPES, MERCHANT_REPORT_VERSIONS, MerchantReportType, @@ -43,6 +44,10 @@ export const BusinessReportSchema = z }) .transform(data => ({ ...data, + status: + data.status === MERCHANT_REPORT_STATUSES_MAP.failed + ? MERCHANT_REPORT_STATUSES_MAP['quality-control'] + : data.status, companyName: data?.companyName ?? (data?.data?.websiteCompanyAnalysis as UnknownRecord | undefined)?.companyName ?? diff --git a/services/workflows-service/src/business-report/business-report.controller.external.ts b/services/workflows-service/src/business-report/business-report.controller.external.ts index 7e30cc9f1..0138f82a2 100644 --- a/services/workflows-service/src/business-report/business-report.controller.external.ts +++ b/services/workflows-service/src/business-report/business-report.controller.external.ts @@ -111,13 +111,24 @@ export class BusinessReportControllerExternal { let business: Pick | undefined; const merchantNameWithDefault = merchantName || 'Not detected'; - if (!businessCorrelationId) { + if (businessCorrelationId) { + business = + (await this.businessService.getByCorrelationId(businessCorrelationId, [currentProjectId], { + select: { + id: true, + correlationId: true, + }, + })) ?? undefined; + } + + if (!business) { business = await this.businessService.create({ data: { companyName: merchantNameWithDefault, country: countryCode, website: websiteUrl, projectId: currentProjectId, + correlationId: businessCorrelationId, }, select: { id: true, @@ -126,16 +137,6 @@ export class BusinessReportControllerExternal { }); } - if (businessCorrelationId) { - business = - (await this.businessService.getByCorrelationId(businessCorrelationId, [currentProjectId], { - select: { - id: true, - correlationId: true, - }, - })) ?? undefined; - } - if (!business) { throw new BadRequestException( `Business with an id of ${businessCorrelationId} was not found`,