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