|
@ -1,6 +1,9 @@ |
|
|
import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface'; |
|
|
import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface'; |
|
|
import { Rule } from '@ghostfolio/api/models/rule'; |
|
|
import { Rule } from '@ghostfolio/api/models/rule'; |
|
|
import { UserSettings } from '@ghostfolio/common/interfaces'; |
|
|
import { |
|
|
|
|
|
PortfolioReportRule, |
|
|
|
|
|
UserSettings |
|
|
|
|
|
} from '@ghostfolio/common/interfaces'; |
|
|
|
|
|
|
|
|
import { Injectable } from '@nestjs/common'; |
|
|
import { Injectable } from '@nestjs/common'; |
|
|
|
|
|
|
|
@ -11,19 +14,23 @@ export class RulesService { |
|
|
public async evaluate<T extends RuleSettings>( |
|
|
public async evaluate<T extends RuleSettings>( |
|
|
aRules: Rule<T>[], |
|
|
aRules: Rule<T>[], |
|
|
aUserSettings: UserSettings |
|
|
aUserSettings: UserSettings |
|
|
) { |
|
|
): Promise<PortfolioReportRule[]> { |
|
|
return aRules.map((rule) => { |
|
|
return aRules.map((rule) => { |
|
|
if (rule.getSettings(aUserSettings)?.isActive) { |
|
|
const settings = rule.getSettings(aUserSettings); |
|
|
const { evaluation, value } = rule.evaluate( |
|
|
|
|
|
rule.getSettings(aUserSettings) |
|
|
if (settings?.isActive) { |
|
|
); |
|
|
const { evaluation, value } = rule.evaluate(settings); |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
evaluation, |
|
|
evaluation, |
|
|
value, |
|
|
value, |
|
|
isActive: true, |
|
|
isActive: true, |
|
|
key: rule.getKey(), |
|
|
key: rule.getKey(), |
|
|
name: rule.getName() |
|
|
name: rule.getName(), |
|
|
|
|
|
settings: <PortfolioReportRule['settings']>{ |
|
|
|
|
|
thresholdMax: settings['thresholdMax'], |
|
|
|
|
|
thresholdMin: settings['thresholdMin'] |
|
|
|
|
|
} |
|
|
}; |
|
|
}; |
|
|
} else { |
|
|
} else { |
|
|
return { |
|
|
return { |
|
|