feat(ynab): add category overspent trigger

This commit is contained in:
Rıdvan Akca
2024-01-18 17:31:53 +03:00
parent 53f7f38e23
commit 1428bf8ffa
3 changed files with 39 additions and 1 deletions

View File

@@ -0,0 +1,35 @@
import defineTrigger from '../../../../helpers/define-trigger.js';
export default defineTrigger({
name: 'Category overspent',
key: 'categoryOverspent',
pollInterval: 15,
description:
'Triggers when a category exceeds its budget, resulting in a negative balance.',
async run($) {
const categoryWithNegativeBalance = [];
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.balance < 0) {
categoryWithNegativeBalance.push(category);
}
});
});
if (categoryWithNegativeBalance?.length) {
for (const category of categoryWithNegativeBalance) {
$.pushTriggerItem({
raw: category,
meta: {
internalId: category.id,
},
});
}
}
},
});

View File

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

View File

@@ -1,6 +1,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: Low account balance
desc: Triggers when the balance of a Checking or Savings account falls below a specified amount within a given month.
---