feat(ynab): add goal completed trigger
This commit is contained in:
@@ -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,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
@@ -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];
|
||||
|
Reference in New Issue
Block a user