Skip to content

Commit

Permalink
fix issue with set relationships block
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Buslaev <[email protected]>
  • Loading branch information
artembuslaev committed May 3, 2023
1 parent 738b805 commit eed4858
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionCallback, BasicBlock } from '@policy-engine/helpers/decorators';
import { ActionCallback, SetRelationshipsBlock as SetRelationships } from '@policy-engine/helpers/decorators';
import { PolicyComponentsUtils } from '@policy-engine/policy-components-utils';
import { IPolicyDocument, IPolicyEventState, IPolicyRequestBlock } from '@policy-engine/policy-engine.interface';
import { IPolicyEvent, PolicyInputEventType, PolicyOutputEventType } from '@policy-engine/interfaces';
Expand All @@ -8,7 +8,7 @@ import { ExternalDocuments, ExternalEvent, ExternalEventType } from '@policy-eng
/**
* Set document relationships action
*/
@BasicBlock({
@SetRelationships({
blockType: 'setRelationshipsBlock',
commonBlock: false,
about: {
Expand Down
33 changes: 18 additions & 15 deletions policy-service/src/policy-engine/helpers/decorators/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
export { SourceAddon } from './source-addon';
export { ExternalData } from './external-data';
export { EventBlock } from './event-block';
export { ContainerBlock } from './container-block';
export { DataSourceBlock } from './data-source-block';
export { BasicBlock } from './basic-block';
export { StateField } from './state-field';
export { CalculateAddon } from './calculate-addon';
export { CalculateBlock } from './calculate-block';
export { Report } from './report-block';
export { ReportItem } from './report-item-block';
export { ActionCallback } from './event-callback';
export { ValidatorBlock } from './validator-block';
export { TokenAddon } from './token-addon';
export { TokenBlock } from './token-block';
export * from './basic-block';
export * from './calculate-addon';
export * from './calculate-block';
export * from './catch-errors';
export * from './container-block';
export * from './data-source-addon';
export * from './data-source-block';
export * from './event-block';
export * from './event-callback';
export * from './external-data';
export * from './report-block';
export * from './report-item-block';
export * from './set-relationships-block';
export * from './source-addon';
export * from './state-field';
export * from './token-addon';
export * from './token-block';
export * from './validator-block';
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { PolicyBlockDecoratorOptions } from '@policy-engine/interfaces/block-options';
import { BasicBlock } from './basic-block';
import { IPolicyUser } from '@policy-engine/policy-user';

/**
* Set relationships block decorator
* @param options
*/
export function SetRelationshipsBlock(options: Partial<PolicyBlockDecoratorOptions>) {
// tslint:disable-next-line:only-arrow-functions
return function (constructor: new (...args: any) => any): any {
const basicClass = BasicBlock(options)(constructor);

return class extends basicClass {
/**
* Block class name
*/
public readonly blockClassName = 'SetRelationshipsBlock';

/**
* Get sources
* @param user
* @param globalFilters
* @protected
*/
protected async getSources(user: IPolicyUser, globalFilters: any): Promise<any[]> {
const data = [];
for (const child of this.children) {
if (child.blockClassName === 'SourceAddon') {
const childData = await child.getFromSource(user, globalFilters);
for (const item of childData) {
data.push(item);
}
}
}
return data;
}
}
}
}

0 comments on commit eed4858

Please sign in to comment.