ghostfolio/apps/api/src/app/portfolio/rules.service.ts
Thomas Kaul fc4bb71184
Feature/migrate date range setting to user settings (#1239)
* Migrate date range to user settings

* Refactor currency and view mode in the user user settings

* Update changelog
2022-09-10 11:38:06 +02:00

24 lines
722 B
TypeScript

import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface';
import { Rule } from '@ghostfolio/api/models/rule';
import { UserSettings } from '@ghostfolio/common/interfaces';
import { Injectable } from '@nestjs/common';
@Injectable()
export class RulesService {
public constructor() {}
public async evaluate<T extends RuleSettings>(
aRules: Rule<T>[],
aUserSettings: UserSettings
) {
return aRules
.filter((rule) => {
return rule.getSettings(aUserSettings)?.isActive;
})
.map((rule) => {
const evaluationResult = rule.evaluate(rule.getSettings(aUserSettings));
return { ...evaluationResult, name: rule.getName() };
});
}
}