feat(ynab): add low account balance trigger
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import defineApp from '../../helpers/define-app.js';
|
||||
import addAuthHeader from './common/add-auth-header.js';
|
||||
import auth from './auth/index.js';
|
||||
import triggers from './triggers/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'You Need A Budget',
|
||||
@@ -13,4 +14,5 @@ export default defineApp({
|
||||
supportsConnections: true,
|
||||
beforeRequest: [addAuthHeader],
|
||||
auth,
|
||||
triggers,
|
||||
});
|
||||
|
@@ -0,0 +1,3 @@
|
||||
import lowAccountBalance from './low-account-balance/index.js';
|
||||
|
||||
export default [lowAccountBalance];
|
@@ -0,0 +1,39 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'Low account balance',
|
||||
key: 'lowAccountBalance',
|
||||
pollInterval: 15,
|
||||
description:
|
||||
'Triggers when the balance of a Checking or Savings account falls below a specified amount within a given month.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Balance Below Amount',
|
||||
key: 'balanceBelowAmount',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'Account balance falls below this amount (e.g. "250.00")',
|
||||
variables: true,
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const balanceBelowAmount = $.step.parameters.balanceBelowAmount;
|
||||
const formattedBalance = balanceBelowAmount * 1000;
|
||||
|
||||
const response = await $.http.get('/budgets/last-used/accounts');
|
||||
|
||||
if (response.data?.data?.accounts?.length) {
|
||||
for (const account of response.data.data.accounts) {
|
||||
if (account.balance < formattedBalance) {
|
||||
$.pushTriggerItem({
|
||||
raw: account,
|
||||
meta: {
|
||||
internalId: account.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
Reference in New Issue
Block a user