feat(ynab): add goal completed trigger

This commit is contained in:
Rıdvan Akca
2024-01-18 18:00:48 +03:00
parent 1428bf8ffa
commit ab811daba7
3 changed files with 38 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
import defineTrigger from '../../../../helpers/define-trigger.js';
export default defineTrigger({
name: 'Goal completed',
key: 'goalCompleted',
pollInterval: 15,
description: 'Triggers when a goal is completed.',
async run($) {
const goalCompletedCategories = [];
const response = await $.http.get('/budgets/last-used/categories');
const categoryGroups = response.data.data.category_groups;
categoryGroups.forEach((group) => {
group.categories.forEach((category) => {
if (category.goal_percentage_complete === 100) {
goalCompletedCategories.push(category);
}
});
});
if (goalCompletedCategories?.length) {
for (const category of goalCompletedCategories) {
$.pushTriggerItem({
raw: category,
meta: {
internalId: category.id,
},
});
}
}
},
});

View File

@@ -1,4 +1,5 @@
import categoryOverspent from './category-overspent/index.js';
import goalCompleted from './goal-completed/index.js';
import lowAccountBalance from './low-account-balance/index.js';
export default [categoryOverspent, lowAccountBalance];
export default [categoryOverspent, goalCompleted, lowAccountBalance];

View File

@@ -3,6 +3,8 @@ favicon: /favicons/you-need-a-budget.svg
items:
- name: Category overspent
desc: Triggers when a category exceeds its budget, resulting in a negative balance.
- name: Goal completed
desc: Triggers when a goal is completed.
- name: Low account balance
desc: Triggers when the balance of a Checking or Savings account falls below a specified amount within a given month.
---