Skip to content

Commit

Permalink
Notion schema fix and Cron schedule change (#2793)
Browse files Browse the repository at this point in the history
* feat: notion schema fix and Cron schedule change

* feat: test fix
  • Loading branch information
tomer-shvadron authored Oct 22, 2024
1 parent 5448ecd commit 028dcb3
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 10 deletions.
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';
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']),
'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

0 comments on commit 028dcb3

Please sign in to comment.