-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix issue with set relationships block
Signed-off-by: Artem Buslaev <[email protected]>
- Loading branch information
1 parent
738b805
commit eed4858
Showing
3 changed files
with
60 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 18 additions & 15 deletions
33
policy-service/src/policy-engine/helpers/decorators/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
40 changes: 40 additions & 0 deletions
40
policy-service/src/policy-engine/helpers/decorators/set-relationships-block.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |