Skip to content

Commit

Permalink
fix: fix subject issue
Browse files Browse the repository at this point in the history
  • Loading branch information
liorzblrn committed Dec 17, 2024
1 parent a82ff89 commit fac0d4b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion services/workflows-service/src/alert/alert.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class AlertRepository {
}

async findFirst<T extends Pick<Prisma.AlertFindFirstArgs, 'where' | 'orderBy'>>(
args: Prisma.SelectSubset<T, Pick<Prisma.AlertFindFirstArgs, 'where' | 'orderBy'>>,
args: Prisma.SelectSubset<T, Pick<Prisma.AlertFindFirstArgs, 'where' | 'orderBy' | 'include'>>,
projectIds: TProjectIds,
) {
const queryArgs = this.scopeService.scopeFindFirst(args, projectIds);
Expand Down
10 changes: 8 additions & 2 deletions services/workflows-service/src/alert/alert.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit fac0d4b

Please sign in to comment.