diff --git a/services/workflows-service/src/alert/alert.repository.ts b/services/workflows-service/src/alert/alert.repository.ts index 31010f290e..4078850a9e 100644 --- a/services/workflows-service/src/alert/alert.repository.ts +++ b/services/workflows-service/src/alert/alert.repository.ts @@ -18,7 +18,7 @@ export class AlertRepository { } async findFirst>( - args: Prisma.SelectSubset>, + args: Prisma.SelectSubset>, projectIds: TProjectIds, ) { const queryArgs = this.scopeService.scopeFindFirst(args, projectIds); diff --git a/services/workflows-service/src/alert/alert.service.ts b/services/workflows-service/src/alert/alert.service.ts index e4625a1a47..9967680934 100644 --- a/services/workflows-service/src/alert/alert.service.ts +++ b/services/workflows-service/src/alert/alert.service.ts @@ -24,6 +24,7 @@ import { DedupeWindow, TDedupeStrategy, TExecutionDetails } from './types'; import { computeHash } from '@ballerine/common'; import { convertTimeUnitToMilliseconds } from '@/data-analytics/utils'; import { DataInvestigationService } from '@/data-analytics/data-investigation.service'; +import { equals } from 'class-validator'; const DEFAULT_DEDUPE_STRATEGIES = { cooldownTimeframeInMinutes: 60 * 24, @@ -63,12 +64,17 @@ export class AlertService { async getAlertWithDefinition( alertId: string, projectId: string, + monitoringType: MonitoringType, ): Promise<(Alert & { alertDefinition: AlertDefinition }) | null> { - const alert = await this.alertRepository.findById( - alertId, + const alert = await this.alertRepository.findFirst( { where: { id: alertId, + alertDefinition: { + monitoringType: { + equals: monitoringType, + }, + }, }, include: { alertDefinition: true, diff --git a/services/workflows-service/src/data-analytics/data-investigation.service.ts b/services/workflows-service/src/data-analytics/data-investigation.service.ts index e150e85cec..e9a901e063 100644 --- a/services/workflows-service/src/data-analytics/data-investigation.service.ts +++ b/services/workflows-service/src/data-analytics/data-investigation.service.ts @@ -20,7 +20,7 @@ import { export class DataInvestigationService { constructor(protected readonly logger: AppLoggerService) {} - getInvestigationFilter(projectId: string, inlineRule: InlineRule, subject: SubjectRecord) { + getInvestigationFilter(projectId: string, inlineRule: InlineRule, subject?: SubjectRecord) { let investigationFilter; switch (inlineRule.fnInvestigationName) { @@ -91,7 +91,19 @@ export class DataInvestigationService { } return { - ...subject, + // TODO: Backward compatibility, Remove this when all rules are updated, this is a temporary fix + ...(subject?.counterpartyId && + (inlineRule.subjects[0] === 'counterpartyOriginatorId' || + inlineRule.subjects[0] === 'counterpartyBeneficiaryId') && { + [inlineRule.subjects[0]]: subject.counterpartyId, + }), + ...(subject?.counterpartyOriginatorId && { + counterpartyOriginatorId: subject.counterpartyOriginatorId, + }), + ...(subject?.counterpartyBeneficiaryId && { + counterpartyBeneficiaryId: subject?.counterpartyBeneficiaryId, + }), + ...investigationFilter, ...this._buildTransactionsFiltersByAlert(inlineRule), projectId,