Skip to content

Commit

Permalink
fix: correlation id and failed reports
Browse files Browse the repository at this point in the history
  • Loading branch information
MatanYadaev committed Nov 18, 2024
1 parent db43887 commit 1b07ca3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
5 changes: 5 additions & 0 deletions apps/backoffice-v2/src/domains/business-reports/fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 ??
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,24 @@ export class BusinessReportControllerExternal {
let business: Pick<Business, 'id' | 'correlationId'> | 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,
Expand All @@ -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`,
Expand Down

0 comments on commit 1b07ca3

Please sign in to comment.