Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notion schema fix and Cron schedule change #2793

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/common/src/rule-engine/operators/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const OPERATION = {
LAST_YEAR: 'LAST_YEAR',
EXISTS: 'EXISTS',
IN: 'IN',
IN_CASE_INSENSITIVE: 'IN_CASE_INSENSITIVE',
NOT_IN: 'NOT_IN',
AML_CHECK: 'AML_CHECK',
} as const;
Expand All @@ -24,6 +25,7 @@ export const OPERATIONS = [
OPERATION.LAST_YEAR,
OPERATION.EXISTS,
OPERATION.IN,
OPERATION.IN_CASE_INSENSITIVE,
OPERATION.NOT_IN,
OPERATION.AML_CHECK,
];
Expand Down
14 changes: 10 additions & 4 deletions packages/common/src/rule-engine/rules/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { z } from 'zod';

import { OPERATION, OPERATOR } from '../operators/enums';
import { RuleSet } from './types';
import {
OPERATION,
OPERATOR,
AmlCheckSchema,
BetweenSchema,
ExistsSchema,
LastYearsSchema,
PrimitiveArraySchema,
PrimitiveSchema,
} from '../operators/schemas';
} from '@/rule-engine';

export function getValues<T extends Record<string, unknown>>(obj: T) {
export const getValues = <T extends Record<string, unknown>>(obj: T) => {
return Object.values(obj) as [(typeof obj)[keyof T]];
}
};

export const RuleSchema = z.discriminatedUnion('operator', [
z.object({
Expand Down Expand Up @@ -79,6 +80,11 @@ export const RuleSchema = z.discriminatedUnion('operator', [
operator: z.literal(OPERATION.IN),
value: PrimitiveArraySchema,
}),
z.object({
key: z.string(),
operator: z.literal(OPERATION.IN_CASE_INSENSITIVE),
value: PrimitiveArraySchema,
}),
z.object({
key: z.string(),
operator: z.literal(OPERATION.NOT_IN),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export interface RiskRulesPluginParams {
id: string;
domain: string;
indicator: string;
riskLevel: 'critical' | 'moderate' | 'positive';
riskLevel: 'critical' | 'high' | 'moderate' | 'positive';
tomer-shvadron marked this conversation as resolved.
Show resolved Hide resolved
baseRiskScore: number;
additionalRiskScore: number;
result: RuleResultSet;
Expand Down
2 changes: 1 addition & 1 deletion services/workflows-service/prisma/data-migrations
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ describe('Rule Engine', () => {
"LTE",
"EXISTS",
"IN",
"IN_CASE_INSENSITIVE",
"NOT_IN"
],
"path": [
"operator"
],
"message": "Invalid discriminator value. Expected 'LAST_YEAR' | 'AML_CHECK' | 'EQUALS' | 'NOT_EQUALS' | 'BETWEEN' | 'GT' | 'LT' | 'GTE' | 'LTE' | 'EXISTS' | 'IN' | 'NOT_IN'"
"message": "Invalid discriminator value. Expected 'LAST_YEAR' | 'AML_CHECK' | 'EQUALS' | 'NOT_EQUALS' | 'BETWEEN' | 'GT' | 'LT' | 'GTE' | 'LTE' | 'EXISTS' | 'IN' | 'IN_CASE_INSENSITIVE' | 'NOT_IN'"
}
],
"name": "ZodError"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fetchServiceFromModule } from '@/test/helpers/nest-app-helper';
import { NotionService } from './../notion/notion.service';
import { NotionService } from '../notion/notion.service';
import { RiskRuleService } from './risk-rule.service';

// We should inject notion api key in order to run it during CI pipeline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const NotionRiskRuleRecordSchema = z
.pipe(RuleSetSchema),
Domain: z.string().min(1),
Indicator: z.string().min(1),
'Risk level': z.enum(['positive', 'moderate', 'critical']),
'Risk level': z.enum(['positive', 'moderate', 'high', 'critical']),
tomer-shvadron marked this conversation as resolved.
Show resolved Hide resolved
'Base risk score': z.number().min(0).max(100),
'Additional risk score': z.number().min(0).max(100),
'Min risk score': z.number().min(0).max(100),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class OngoingMonitoringCron {
protected readonly businessReportService: BusinessReportService,
) {}

@Cron(CronExpression.EVERY_MINUTE)
@Cron(CronExpression.EVERY_HOUR)
async handleCron() {
this.logger.log('Ongoing monitoring cron started');

Expand Down
Loading