-
Notifications
You must be signed in to change notification settings - Fork 0
/
registerAll.js
89 lines (80 loc) · 4.93 KB
/
registerAll.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const getField = require('./fields/getField');
// Triggers
const AccountBalanceTrigger = require('./triggers/AccountBalanceTrigger');
const TransactionAddedTrigger = require('./triggers/TransactionAddedTrigger');
const AgeOfMoneyTrigger = require('./triggers/AgeOfMoneyTrigger');
const BudgetThresholdTrigger = require('./triggers/BudgetThresholdTrigger');
const ScheduledTransactionTrigger = require('./triggers/ScheduledTransactionTrigger');
const AccountTriggerField = getField({ type: 'trigger', slug: 'account' });
const CategoryTriggerField = getField({ type: 'trigger', slug: 'category' });
const PayeeTriggerField = getField({ type: 'trigger', slug: 'payee' });
const MinValueTriggerField = getField({ type: 'trigger', slug: 'minimum_value' });
const MaxValueTriggerField = getField({ type: 'trigger', slug: 'maximum_value' });
const MinOutflowTriggerField = getField({ type: 'trigger', slug: 'minimum_outflow' });
const MinInflowTriggerField = getField({ type: 'trigger', slug: 'minimum_inflow' });
const FlagColorTriggerField = getField({ type: 'trigger', slug: 'flag_color' });
const DaysBeforeTriggerField = getField({ type: 'trigger', slug: 'days_before' });
const PercentUsedTriggerField = getField({ type: 'trigger',slug: 'percent_used' });
const AmountRemainingTriggerField = getField({type: 'trigger',slug: 'amount_remaining',});
// Actions
const AddTransactionAction = require('./actions/AddTransactionAction');
const UpdateTransactionAction = require('./actions/UpdateTransactionAction');
const CategoryActionField = getField({ type: 'action', slug: 'category' });
const PayeeActionField = getField({ type: 'action', slug: 'payee' });
const AccountActionField = getField({ type: 'action', slug: 'account' });
const TransactionIDActionField = getField({type: 'action', slug: 'transaction_id' });
const AmountActionField = getField({ type: 'action', slug: 'amount' });
const FlagColorActionField = getField({ type: 'action', slug: 'flag_color' });
const ClearedActionField = getField({ type: 'action', slug: 'cleared' });
function registerAll(ynabApi) {
// Register AccountBalanceTrigger
const accountBalanceTrigger = new AccountBalanceTrigger();
accountBalanceTrigger.registerField(new AccountTriggerField());
accountBalanceTrigger.registerField(new MinValueTriggerField());
accountBalanceTrigger.registerField(new MaxValueTriggerField());
ynabApi.registerTrigger(accountBalanceTrigger);
// Register TransactionAddedTrigger
const transactionAddedTrigger = new TransactionAddedTrigger();
transactionAddedTrigger.registerField(new CategoryTriggerField());
transactionAddedTrigger.registerField(new PayeeTriggerField());
transactionAddedTrigger.registerField(new AccountTriggerField());
transactionAddedTrigger.registerField(new MinOutflowTriggerField());
transactionAddedTrigger.registerField(new MinInflowTriggerField());
transactionAddedTrigger.registerField(new FlagColorTriggerField());
ynabApi.registerTrigger(transactionAddedTrigger);
// Register AgeOfMoneyTrigger
const ageOfMoneyTrigger = new AgeOfMoneyTrigger();
ageOfMoneyTrigger.registerField(new MinValueTriggerField());
ageOfMoneyTrigger.registerField(new MaxValueTriggerField());
ynabApi.registerTrigger(ageOfMoneyTrigger);
// Register ScheduledTransactionTrigger
const scheduledTransactionTrigger = new ScheduledTransactionTrigger();
scheduledTransactionTrigger.registerField(new DaysBeforeTriggerField());
ynabApi.registerTrigger(scheduledTransactionTrigger);
// Register AgeOfMoneyTrigger
const budgetThresholdTrigger = new BudgetThresholdTrigger();
budgetThresholdTrigger.registerField(new PercentUsedTriggerField());
budgetThresholdTrigger.registerField(new AmountRemainingTriggerField());
budgetThresholdTrigger.registerField(new CategoryTriggerField());
ynabApi.registerTrigger(budgetThresholdTrigger);
// Register Add Transaction action
const addTransactionAction = new AddTransactionAction();
addTransactionAction.registerField(new CategoryActionField());
addTransactionAction.registerField(new PayeeActionField());
addTransactionAction.registerField(new AccountActionField());
addTransactionAction.registerField(new AmountActionField());
addTransactionAction.registerField(new FlagColorActionField());
addTransactionAction.registerField(new ClearedActionField());
ynabApi.registerAction(addTransactionAction);
// Register Update Transaction action
const updateTransactionAction = new UpdateTransactionAction();
updateTransactionAction.registerField(new CategoryActionField());
updateTransactionAction.registerField(new PayeeActionField());
updateTransactionAction.registerField(new AccountActionField());
updateTransactionAction.registerField(new TransactionIDActionField());
updateTransactionAction.registerField(new AmountActionField());
updateTransactionAction.registerField(new FlagColorActionField());
updateTransactionAction.registerField(new ClearedActionField());
ynabApi.registerAction(updateTransactionAction);
}
module.exports = registerAll;