Skip to content

Commit

Permalink
fix: counterparty subject fix
Browse files Browse the repository at this point in the history
  • Loading branch information
liorzblrn committed Dec 19, 2024
1 parent 5e041a9 commit 0c46a45
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SubjectRecord } from '@/alert/types';
import { ALERT_DEFINITIONS } from './../../scripts/alerts/generate-alerts';
import { SubjectRecord, TExecutionDetails } from '@/alert/types';
import { AppLoggerService } from '@/common/app-logger/app-logger.service';
import { Injectable } from '@nestjs/common';
import { Alert, PaymentMethod, Prisma, TransactionRecordType } from '@prisma/client';
Expand All @@ -15,6 +16,7 @@ import {
TPeerGroupTransactionAverageOptions,
TransactionsAgainstDynamicRulesType,
} from './types';
import type { AlertService } from '@/alert/alert.service';

@Injectable()
export class DataInvestigationService {
Expand Down Expand Up @@ -92,6 +94,36 @@ export class DataInvestigationService {

return {
// TODO: Backward compatibility, Remove this when all rules are updated, this is a temporary fix
...investigationFilter,
...this.buildSubjectFilterCompetability(inlineRule, subject),
...this._buildTransactionsFiltersByAlert(inlineRule),
projectId,
} satisfies Prisma.TransactionRecordWhereInput;
}

// TODO: can be removed after all rules are updated, support for subjects in the alert
buildSubjectFilterCompetabilityByAlert(
alert: NonNullable<Awaited<ReturnType<AlertService['getAlertWithDefinition']>>>,
) {
const inlineRule =
ALERT_DEFINITIONS[alert.alertDefinition.ruleId as keyof typeof ALERT_DEFINITIONS]?.inlineRule;

if (!inlineRule) {
this.logger.error(`Couldnt find related alert definition by ruleId`, {
alert,
});

return {};
}

const subject = (alert.executionDetails as TExecutionDetails).subject;

return this.buildSubjectFilterCompetability(inlineRule, subject);
}

// TODO: can be removed after all rules are updated
buildSubjectFilterCompetability(inlineRule: InlineRule, subject?: SubjectRecord) {
return {
...(subject?.counterpartyId &&
(inlineRule.subjects[0] === 'counterpartyOriginatorId' ||
inlineRule.subjects[0] === 'counterpartyBeneficiaryId') && {
Expand All @@ -103,11 +135,7 @@ export class DataInvestigationService {
...(subject?.counterpartyBeneficiaryId && {
counterpartyBeneficiaryId: subject?.counterpartyBeneficiaryId,
}),

...investigationFilter,
...this._buildTransactionsFiltersByAlert(inlineRule),
projectId,
} satisfies Prisma.TransactionRecordWhereInput;
};
}

investigateTransactionsAgainstDynamicRules(options: TransactionsAgainstDynamicRulesType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,10 @@ export class TransactionControllerExternal {
alert: NonNullable<Awaited<ReturnType<AlertService['getAlertWithDefinition']>>>;
filters: Pick<GetTransactionsByAlertDto, 'startDate' | 'endDate' | 'page' | 'orderBy'>;
}) {
const subject = this.dataInvestigationService.buildSubjectFilterCompetabilityByAlert(alert);

return this.service.getTransactions(projectId, filters, {
where: alert.executionDetails.filters,
where: { ...alert.executionDetails.filters, ...subject },
include: {
counterpartyBeneficiary: {
select: {
Expand Down
1 change: 0 additions & 1 deletion services/workflows-service/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"sourceRoot": "/", // Shortens file paths on Sentry
"exclude": [
"node_modules",
"prisma/migrations",
"prisma/schema.prisma",
"test",
"dist",
Expand Down

0 comments on commit 0c46a45

Please sign in to comment.