From 5e63620702fa2c273c99c755e901b8d3e4e16135 Mon Sep 17 00:00:00 2001 From: Sasha Mysak Date: Thu, 16 Jan 2025 12:01:59 +0100 Subject: [PATCH] fix: removed merchants metric --- .../business-report.controller.external.ts | 24 ++++++++++++++++++- .../business/business.controller.external.ts | 4 +++- 2 files changed, 26 insertions(+), 2 deletions(-) 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 9a1d5616a7..1817d3d3b8 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 @@ -44,6 +44,7 @@ import { } from '@/business-report/dtos/business-report-metrics.dto'; import { BusinessReportMetricsDto } from './dtos/business-report-metrics-dto'; import { FEATURE_LIST, TCustomerWithFeatures } from '@/customer/types'; +import dayjs from 'dayjs'; @ApiBearerAuth() @swagger.ApiTags('Business Reports') @@ -168,7 +169,28 @@ export class BusinessReportControllerExternal { ) { const { id: customerId } = await this.customerService.getByProjectId(currentProjectId); - return await this.merchantMonitoringClient.getMetrics({ customerId, from, to }); + const unmonitoredMerchants = await this.prismaService.business.count({ + where: { + projectId: currentProjectId, + metadata: { + path: ['featureConfig', FEATURE_LIST.ONGOING_MERCHANT_REPORT, 'disabledAt'], + not: 'null', + ...(from && { gt: dayjs(from).toDate().getTime() }), + ...(to && { lte: dayjs(to).toDate().getTime() }), + }, + }, + }); + + const merchantMonitoringMetrics = await this.merchantMonitoringClient.getMetrics({ + customerId, + from, + to, + }); + + return { + ...merchantMonitoringMetrics, + removedMerchantsCount: unmonitoredMerchants, + }; } @common.Post() diff --git a/services/workflows-service/src/business/business.controller.external.ts b/services/workflows-service/src/business/business.controller.external.ts index 002e9d8a9b..f3694f3cac 100755 --- a/services/workflows-service/src/business/business.controller.external.ts +++ b/services/workflows-service/src/business/business.controller.external.ts @@ -155,12 +155,14 @@ export class BusinessControllerExternal { featureConfig?: TCustomerWithFeatures['features']; }; + const isEnabled = data.state === 'on'; const updatedMetadata = _.merge({}, metadata, { featureConfig: { [FEATURE_LIST.ONGOING_MERCHANT_REPORT]: { - enabled: data.state === 'on', + enabled: isEnabled, reason: data.reason ?? null, userReason: data.userReason ?? null, + disabledAt: isEnabled ? null : new Date().getTime(), }, }, });