fix(ynab/goal-completed): scope triger by year and month

This commit is contained in:
Ali BARIN
2024-05-08 12:56:46 +00:00
parent 8da3448e9c
commit 92a8c1483d

View File

@@ -1,3 +1,4 @@
import { DateTime } from 'luxon';
import defineTrigger from '../../../../helpers/define-trigger.js';
export default defineTrigger({
@@ -7,6 +8,7 @@ export default defineTrigger({
description: 'Triggers when a goal is completed.',
async run($) {
const monthYear = DateTime.now().toFormat('MM-yyyy');
const goalCompletedCategories = [];
const response = await $.http.get('/budgets/default/categories');
@@ -20,15 +22,13 @@ export default defineTrigger({
});
});
if (goalCompletedCategories?.length) {
for (const category of goalCompletedCategories) {
$.pushTriggerItem({
raw: category,
meta: {
internalId: category.id,
},
});
}
for (const category of goalCompletedCategories) {
$.pushTriggerItem({
raw: category,
meta: {
internalId: `${category.id}-${monthYear}`,
},
});
}
},
});