feat(ynab): add low account balance trigger

This commit is contained in:
Rıdvan Akca
2024-01-18 15:42:28 +03:00
parent ce6ad9e0d3
commit 53f7f38e23
6 changed files with 58 additions and 0 deletions

View File

@@ -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,
});

View File

@@ -0,0 +1,3 @@
import lowAccountBalance from './low-account-balance/index.js';
export default [lowAccountBalance];

View File

@@ -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,
},
});
}
}
}
},
});