From 98a7aac73667241da350169e55edd2fc16a6687f Mon Sep 17 00:00:00 2001 From: youngcw <calebyoung94@gmail.com> Date: Fri, 26 Apr 2024 06:57:52 -0700 Subject: [PATCH] add schedule name check to check templates (#2667) * check schedule name * note --- .../src/server/budget/goaltemplates.ts | 18 +++++++++++++++++- upcoming-release-notes/2667.md | 6 ++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 upcoming-release-notes/2667.md diff --git a/packages/loot-core/src/server/budget/goaltemplates.ts b/packages/loot-core/src/server/budget/goaltemplates.ts index 110a14870..d2d698490 100644 --- a/packages/loot-core/src/server/budget/goaltemplates.ts +++ b/packages/loot-core/src/server/budget/goaltemplates.ts @@ -641,17 +641,33 @@ async function checkTemplates(): Promise<Notification> { const categories = await db.all( 'SELECT * FROM v_categories WHERE tombstone = 0', ); + let all_schedule_names = await db.all( + 'SELECT name from schedules WHERE name NOT NULL AND tombstone = 0', + ); + all_schedule_names = all_schedule_names.map(v => v.name); // run through each line and see if its an error for (let c = 0; c < categories.length; c++) { const category = categories[c]; const template = category_templates[category.id]; + if (template) { for (let l = 0; l < template.length; l++) { + //check for basic error if (template[l].type === 'error') { - //return { type: 'message', message: "found a bad one",}; errors.push(category.name + ': ' + template[l].line); } + // check schedule name error + if (template[l].type === 'schedule') { + if (!all_schedule_names.includes(template[l].name)) { + errors.push( + category.name + + ': Schedule “' + + template[l].name + + '†does not exist', + ); + } + } } } } diff --git a/upcoming-release-notes/2667.md b/upcoming-release-notes/2667.md new file mode 100644 index 000000000..0c8c9fa20 --- /dev/null +++ b/upcoming-release-notes/2667.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [youngcw] +--- + +Check schedule name when using the check templates function -- GitLab