mirror of https://github.com/ghostfolio/ghostfolio
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
47 lines
1.3 KiB
import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface';
|
|
import { Rule } from '@ghostfolio/api/models/rule';
|
|
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service';
|
|
import { UserSettings } from '@ghostfolio/common/interfaces';
|
|
|
|
export class EmergencyFundSetup extends Rule<Settings> {
|
|
private emergencyFund: number;
|
|
|
|
public constructor(
|
|
protected exchangeRateDataService: ExchangeRateDataService,
|
|
emergencyFund: number
|
|
) {
|
|
super(exchangeRateDataService, {
|
|
key: EmergencyFundSetup.name,
|
|
name: 'Emergency Fund: Set up'
|
|
});
|
|
|
|
this.emergencyFund = emergencyFund;
|
|
}
|
|
|
|
public evaluate(ruleSettings: Settings) {
|
|
if (this.emergencyFund < ruleSettings.thresholdMin) {
|
|
return {
|
|
evaluation: 'No emergency fund has been set up',
|
|
value: false
|
|
};
|
|
}
|
|
|
|
return {
|
|
evaluation: 'An emergency fund has been set up',
|
|
value: true
|
|
};
|
|
}
|
|
|
|
public getSettings(aUserSettings: UserSettings): Settings {
|
|
return {
|
|
baseCurrency: aUserSettings.baseCurrency,
|
|
isActive: aUserSettings.xRayRules[this.getKey()].isActive,
|
|
thresholdMin: 0
|
|
};
|
|
}
|
|
}
|
|
|
|
interface Settings extends RuleSettings {
|
|
baseCurrency: string;
|
|
thresholdMin: number;
|
|
}
|
|
|