Skip to content

Commit

Permalink
Merge pull request #23 from bcgov/feature/nested-rulemaps
Browse files Browse the repository at this point in the history
Feature - input / output rulemaps for linked rules
  • Loading branch information
brysonjbest authored Jul 24, 2024
2 parents 590a4df + dfd9057 commit e2c41fc
Show file tree
Hide file tree
Showing 7 changed files with 649 additions and 84 deletions.
4 changes: 2 additions & 2 deletions src/api/ruleMapping/ruleMapping.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('RuleMappingController', () => {
const ruleFileName = 'test-rule.json';
const ruleContent = { nodes: [], edges: [] };
const rulemap = { inputs: [], outputs: [], resultOutputs: [] };
jest.spyOn(service, 'ruleSchema').mockReturnValue(rulemap);
jest.spyOn(service, 'ruleSchema').mockResolvedValue(rulemap);

const mockResponse = {
setHeader: jest.fn(),
Expand All @@ -65,7 +65,7 @@ describe('RuleMappingController', () => {
const nodes = [{ id: '1', type: 'someType', content: { inputs: [], outputs: [] } }];
const edges = [{ id: '2', type: 'someType', targetId: '1', sourceId: '1' }];
const result = { inputs: [], outputs: [], resultOutputs: [] };
jest.spyOn(service, 'ruleSchema').mockReturnValue(result);
jest.spyOn(service, 'ruleSchema').mockResolvedValue(result);

const dto: EvaluateRuleMappingDto = { nodes, edges };
const response = await controller.evaluateRuleMap(dto);
Expand Down
4 changes: 2 additions & 2 deletions src/api/ruleMapping/ruleMapping.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class RuleMappingController {
@Body('ruleContent') ruleContent: EvaluateRuleMappingDto,
@Res() res: Response,
) {
const rulemap = this.ruleMappingService.ruleSchema(ruleContent);
const rulemap = await this.ruleMappingService.ruleSchema(ruleContent);

try {
res.setHeader('Content-Type', 'application/json');
Expand All @@ -33,7 +33,7 @@ export class RuleMappingController {
@Post('/evaluate')
async evaluateRuleMap(@Body() ruleContent: EvaluateRuleMappingDto) {
try {
const result = this.ruleMappingService.ruleSchema(ruleContent);
const result = await this.ruleMappingService.ruleSchema(ruleContent);
return { result };
} catch (error) {
if (error instanceof InvalidRuleContent) {
Expand Down
7 changes: 5 additions & 2 deletions src/api/ruleMapping/ruleMapping.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export interface Field {

export interface InputField extends Field {}

export interface OutputField extends Field {}
export interface OutputField extends Field {
exception?: string;
}

export interface Expression {
key: string;
Expand All @@ -20,12 +22,13 @@ export interface NodeContent {
inputs?: InputField[];
outputs?: OutputField[];
expressions?: Expression[];
key?: string;
}

export interface Node {
id: any;
type: string;
content: NodeContent;
content: NodeContent | string;
}

export interface Edge {
Expand Down
Loading

0 comments on commit e2c41fc

Please sign in to comment.