Skip to content

Commit

Permalink
fix: removed merchants metric
Browse files Browse the repository at this point in the history
  • Loading branch information
r4zendev committed Jan 16, 2025
1 parent 37ccb73 commit 5e63620
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
},
});
Expand Down

0 comments on commit 5e63620

Please sign in to comment.