Skip to content

A local-first personal finance app

Add backend logic to support automations UI (#5532)

Julian Dominguez-Schatzebde78434a40
diff --git a/packages/desktop-client/src/components/budget/goals/BudgetAutomation.tsx b/packages/desktop-client/src/components/budget/goals/BudgetAutomation.tsx
index 9f25891438..41a93c4ea2 100644
--- a/packages/desktop-client/src/components/budget/goals/BudgetAutomation.tsx
+++ b/packages/desktop-client/src/components/budget/goals/BudgetAutomation.tsx
@@ -12,7 +12,7 @@ import { type Template } from 'loot-core/types/models/templates';
import { type Action } from './actions';
import { BudgetAutomationEditor } from './BudgetAutomationEditor';
import { BudgetAutomationReadOnly } from './BudgetAutomationReadOnly';
-import { getInitialState, templateReducer } from './reducer';
+import { DEFAULT_PRIORITY, getInitialState, templateReducer } from './reducer';
type BudgetAutomationProps = {
categories: CategoryGroupEntity[];
@@ -26,9 +26,10 @@ type BudgetAutomationProps = {
};
const DEFAULT_TEMPLATE: Template = {
- directive: '',
+ directive: 'template',
type: 'simple',
monthly: 0,
+ priority: DEFAULT_PRIORITY,
};
export const BudgetAutomation = ({
diff --git a/packages/desktop-client/src/components/budget/goals/actions.ts b/packages/desktop-client/src/components/budget/goals/actions.ts
index f11b2a5a01..f100085496 100644
--- a/packages/desktop-client/src/components/budget/goals/actions.ts
+++ b/packages/desktop-client/src/components/budget/goals/actions.ts
@@ -14,7 +14,7 @@ type SET_TEMPLATE = {
type UPDATE_TEMPLATE = {
type: 'update-template';
- payload: Partial<Template>;
+ payload: Partial<Template> & Pick<Template, 'type'>;
};
export const setType = (type: DisplayTemplateType): SET_TYPE => ({
@@ -28,7 +28,7 @@ export const setTemplate = (template: Template): SET_TEMPLATE => ({
});
export const updateTemplate = (
- template: Partial<Template>,
+ template: Partial<Template> & Pick<Template, 'type'>,
): UPDATE_TEMPLATE => ({
type: 'update-template' as const,
payload: template,
diff --git a/packages/desktop-client/src/components/budget/goals/editor/HistoricalAutomation.tsx b/packages/desktop-client/src/components/budget/goals/editor/HistoricalAutomation.tsx
index 19986ea4da..1283e18f36 100644
--- a/packages/desktop-client/src/components/budget/goals/editor/HistoricalAutomation.tsx
+++ b/packages/desktop-client/src/components/budget/goals/editor/HistoricalAutomation.tsx
@@ -62,8 +62,8 @@ export const HistoricalAutomation = ({
dispatch(
updateTemplate(
template.type === 'average'
- ? { numMonths: value }
- : { lookBack: value },
+ ? { type: 'average', numMonths: value }
+ : { type: 'copy', lookBack: value },
),
)
}
diff --git a/packages/desktop-client/src/components/budget/goals/reducer.ts b/packages/desktop-client/src/components/budget/goals/reducer.ts
index 91e18a46bb..986d7e4c31 100644
--- a/packages/desktop-client/src/components/budget/goals/reducer.ts
+++ b/packages/desktop-client/src/components/budget/goals/reducer.ts
@@ -3,6 +3,8 @@ import { type Template } from 'loot-core/types/models/templates';
import { type Action } from './actions';
import { type ReducerState, type DisplayTemplateType } from './constants';
+export const DEFAULT_PRIORITY = 1;
+
export const getInitialState = (template: Template | null): ReducerState => {
const type = template?.type;
switch (type) {
@@ -58,9 +60,10 @@ const changeType = (
return {
displayType: visualType,
template: {
- directive: '',
+ directive: 'template',
type: 'simple',
monthly: 500,
+ priority: DEFAULT_PRIORITY,
},
};
case 'percentage':
@@ -70,11 +73,12 @@ const changeType = (
return {
displayType: visualType,
template: {
- directive: '',
+ directive: 'template',
type: 'percentage',
percent: 15,
previous: false,
category: 'total',
+ priority: DEFAULT_PRIORITY,
},
};
case 'schedule':
@@ -84,9 +88,10 @@ const changeType = (
return {
displayType: visualType,
template: {
- directive: '',
+ directive: 'template',
type: 'schedule',
name: '',
+ priority: DEFAULT_PRIORITY,
},
};
case 'week':
@@ -96,7 +101,7 @@ const changeType = (
return {
displayType: visualType,
template: {
- directive: '',
+ directive: 'template',
type: 'periodic',
amount: 500,
period: {
@@ -104,6 +109,7 @@ const changeType = (
amount: 1,
},
starting: '',
+ priority: DEFAULT_PRIORITY,
},
};
case 'historical':
@@ -116,9 +122,10 @@ const changeType = (
return {
displayType: visualType,
template: {
- directive: '',
+ directive: 'template',
type: 'average',
numMonths: 3,
+ priority: DEFAULT_PRIORITY,
},
};
default:
@@ -129,7 +136,7 @@ const changeType = (
function mapTemplateTypesForUpdate(
state: ReducerState,
- template: Partial<Template>,
+ template: Partial<Template> & Pick<Template, 'type'>,
): ReducerState {
switch (state.template.type) {
case 'average':
@@ -140,9 +147,10 @@ function mapTemplateTypesForUpdate(
displayType: 'historical',
template: {
...template,
- directive: '',
+ directive: 'template',
type: 'copy',
lookBack: state.template.numMonths,
+ priority: state.template.priority,
},
};
default:
@@ -157,9 +165,10 @@ function mapTemplateTypesForUpdate(
displayType: 'historical',
template: {
...template,
- directive: '',
+ directive: 'template',
type: 'average',
numMonths: state.template.lookBack,
+ priority: state.template.priority,
},
};
default:
@@ -170,8 +179,8 @@ function mapTemplateTypesForUpdate(
break;
}
- if (!template.type || state.template.type === template.type) {
- const { type: _, ...rest } = template;
+ if (state.template.type === template.type) {
+ const { type: _1, directive: _2, ...rest } = template;
return {
...state,
...getInitialState({
diff --git a/packages/desktop-client/src/components/modals/BudgetAutomationsModal.tsx b/packages/desktop-client/src/components/modals/BudgetAutomationsModal.tsx
index a8f1b20166..c356e12fb3 100644
--- a/packages/desktop-client/src/components/modals/BudgetAutomationsModal.tsx
+++ b/packages/desktop-client/src/components/modals/BudgetAutomationsModal.tsx
@@ -10,6 +10,7 @@ import { q } from 'loot-core/shared/query';
import { type Template } from 'loot-core/types/models/templates';
import { BudgetAutomation } from '@desktop-client/components/budget/goals/BudgetAutomation';
+import { DEFAULT_PRIORITY } from '@desktop-client/components/budget/goals/reducer';
import { useBudgetAutomationCategories } from '@desktop-client/components/budget/goals/useBudgetAutomationCategories';
import {
Modal,
@@ -29,7 +30,8 @@ export function BudgetAutomationsModal() {
{
type: 'average',
numMonths: 3,
- directive: '',
+ directive: 'template',
+ priority: DEFAULT_PRIORITY,
id: uniqueId(),
},
]);
@@ -44,7 +46,13 @@ export function BudgetAutomationsModal() {
const onAdd = () => {
setTemplates([
...templates,
- { type: 'average', numMonths: 3, directive: '', id: uniqueId() },
+ {
+ type: 'average',
+ numMonths: 3,
+ directive: 'template',
+ priority: DEFAULT_PRIORITY,
+ id: uniqueId(),
+ },
]);
};
const onSave = () => {};
diff --git a/packages/loot-core/migrations/1754611200000_add_category_template_settings.sql b/packages/loot-core/migrations/1754611200000_add_category_template_settings.sql
new file mode 100644
index 0000000000..2c2628f3aa
--- /dev/null
+++ b/packages/loot-core/migrations/1754611200000_add_category_template_settings.sql
@@ -0,0 +1,5 @@
+-- Add a column to track where a category's automation templates come from
+-- Allowed values for source (by convention): 'notes' | 'ui'
+ALTER TABLE categories ADD COLUMN template_settings JSON DEFAULT '{"source": "notes"}';
+
+UPDATE categories SET template_settings = '{"source": "ui"}' WHERE template_settings IS NULL;
diff --git a/packages/loot-core/src/server/aql/schema/index.ts b/packages/loot-core/src/server/aql/schema/index.ts
index 606116af55..00262f2b8e 100644
--- a/packages/loot-core/src/server/aql/schema/index.ts
+++ b/packages/loot-core/src/server/aql/schema/index.ts
@@ -85,6 +85,7 @@ export const schema = {
hidden: f('boolean'),
group: f('id', { ref: 'category_groups' }),
goal_def: f('string'),
+ template_settings: f('json', { default: { source: 'notes' } }),
sort_order: f('float'),
tombstone: f('boolean'),
},
diff --git a/packages/loot-core/src/server/budget/app.ts b/packages/loot-core/src/server/budget/app.ts
index 1a23673059..aae2c31326 100644
--- a/packages/loot-core/src/server/budget/app.ts
+++ b/packages/loot-core/src/server/budget/app.ts
@@ -54,6 +54,8 @@ export interface BudgetHandlers {
'category-group-move': typeof moveCategoryGroup;
'category-group-delete': typeof deleteCategoryGroup;
'must-category-transfer': typeof isCategoryTransferRequired;
+ 'budget/get-category-automations': typeof goalActions.getTemplatesForCategory;
+ 'budget/set-category-automations': typeof goalActions.storeTemplates;
}
export const app = createApp<BudgetHandlers>();
@@ -140,6 +142,15 @@ app.method('category-group-move', mutator(undoable(moveCategoryGroup)));
app.method('category-group-delete', mutator(undoable(deleteCategoryGroup)));
app.method('must-category-transfer', isCategoryTransferRequired);
+app.method(
+ 'budget/get-category-automations',
+ goalActions.getTemplatesForCategory,
+);
+app.method(
+ 'budget/set-category-automations',
+ mutator(undoable(goalActions.storeTemplates)),
+);
+
// Server must return AQL entities not the raw DB data
async function getCategories() {
const categoryGroups = await getCategoryGroups();
diff --git a/packages/loot-core/src/server/budget/category-template-context.test.ts b/packages/loot-core/src/server/budget/category-template-context.test.ts
index 8701e991f8..4a022d91ea 100644
--- a/packages/loot-core/src/server/budget/category-template-context.test.ts
+++ b/packages/loot-core/src/server/budget/category-template-context.test.ts
@@ -771,6 +771,7 @@ describe('CategoryTemplateContext', () => {
type: 'remainder',
weight: 2,
directive: 'template',
+ priority: null,
},
];
const instance = new TestCategoryTemplateContext(
@@ -796,6 +797,7 @@ describe('CategoryTemplateContext', () => {
type: 'remainder',
weight: 1,
directive: 'template',
+ priority: null,
},
];
const instance = new TestCategoryTemplateContext(
@@ -821,6 +823,7 @@ describe('CategoryTemplateContext', () => {
type: 'remainder',
weight: 1,
directive: 'template',
+ priority: null,
},
];
const instance = new TestCategoryTemplateContext(
@@ -860,6 +863,7 @@ describe('CategoryTemplateContext', () => {
type: 'remainder',
weight: 1,
directive: 'template',
+ priority: null,
},
];
@@ -983,6 +987,7 @@ describe('CategoryTemplateContext', () => {
type: 'remainder',
weight: 1,
directive: 'template',
+ priority: null,
},
];
diff --git a/packages/loot-core/src/server/budget/category-template-context.ts b/packages/loot-core/src/server/budget/category-template-context.ts
index 2cd7a70106..6e6df8c07d 100644
--- a/packages/loot-core/src/server/budget/category-template-context.ts
+++ b/packages/loot-core/src/server/budget/category-template-context.ts
@@ -133,7 +133,9 @@ export class CategoryTemplateContext {
if (!this.priorities.has(priority)) return 0;
if (this.limitMet) return 0;
- const t = this.templates.filter(t => t.priority === priority);
+ const t = this.templates.filter(
+ t => t.directive === 'template' && t.priority === priority,
+ );
let available = budgetAvail || 0;
let toBudget = 0;
let byFlag = false;
diff --git a/packages/loot-core/src/server/budget/goal-template.ts b/packages/loot-core/src/server/budget/goal-template.ts
index cd53205d7a..88cebb88bd 100644
--- a/packages/loot-core/src/server/budget/goal-template.ts
+++ b/packages/loot-core/src/server/budget/goal-template.ts
@@ -4,11 +4,12 @@ import { q } from '../../shared/query';
import { CategoryEntity, CategoryGroupEntity } from '../../types/models';
import { Template } from '../../types/models/templates';
import { aqlQuery } from '../aql';
+import * as db from '../db';
import { batchMessages } from '../sync';
import { isReflectBudget, getSheetValue, setGoal, setBudget } from './actions';
import { CategoryTemplateContext } from './category-template-context';
-import { checkTemplates, storeTemplates } from './template-notes';
+import { checkTemplateNotes, storeNoteTemplates } from './template-notes';
type Notification = {
type?: 'message' | 'error' | 'warning' | undefined;
@@ -18,12 +19,35 @@ type Notification = {
sticky?: boolean | undefined;
};
+export async function storeTemplates({
+ categoriesWithTemplates,
+ source,
+}: {
+ categoriesWithTemplates: {
+ id: string;
+ templates: Template[];
+ }[];
+ source: 'notes' | 'ui';
+}): Promise<void> {
+ await batchMessages(async () => {
+ for (const { id, templates } of categoriesWithTemplates) {
+ const goalDefs = JSON.stringify(templates);
+
+ await db.updateWithSchema('categories', {
+ id,
+ goal_def: goalDefs,
+ template_settings: { source },
+ });
+ }
+ });
+}
+
export async function applyTemplate({
month,
}: {
month: string;
}): Promise<Notification> {
- await storeTemplates();
+ await storeNoteTemplates();
const categoryTemplates = await getTemplates();
const ret = await processTemplate(month, false, categoryTemplates);
return ret;
@@ -34,7 +58,7 @@ export async function overwriteTemplate({
}: {
month: string;
}): Promise<Notification> {
- await storeTemplates();
+ await storeNoteTemplates();
const categoryTemplates = await getTemplates();
const ret = await processTemplate(month, true, categoryTemplates);
return ret;
@@ -52,7 +76,7 @@ export async function applyMultipleCategoryTemplates({
.filter({ id: { $oneof: categoryIds } })
.select('*'),
);
- await storeTemplates();
+ await storeNoteTemplates();
const categoryTemplates = await getTemplates(c => categoryIds.includes(c.id));
const ret = await processTemplate(
month,
@@ -73,7 +97,7 @@ export async function applySingleCategoryTemplate({
const { data: categoryData }: { data: CategoryEntity[] } = await aqlQuery(
q('categories').filter({ id: category }).select('*'),
);
- await storeTemplates();
+ await storeNoteTemplates();
const categoryTemplates = await getTemplates(c => c.id === category);
const ret = await processTemplate(
month,
@@ -85,7 +109,7 @@ export async function applySingleCategoryTemplate({
}
export function runCheckTemplates() {
- return checkTemplates();
+ return checkTemplateNotes();
}
async function getCategories(): Promise<CategoryEntity[]> {
@@ -115,6 +139,12 @@ async function getTemplates(
return categoryTemplates;
}
+export async function getTemplatesForCategory(
+ categoryId: CategoryEntity['id'],
+): Promise<Record<CategoryEntity['id'], Template[]>> {
+ return getTemplates(c => c.id === categoryId);
+}
+
type TemplateBudget = {
category: CategoryEntity['id'];
budgeted: number;
diff --git a/packages/loot-core/src/server/budget/schedule-template.test.ts b/packages/loot-core/src/server/budget/schedule-template.test.ts
index 2ae52536ce..8cc5d04a4c 100644
--- a/packages/loot-core/src/server/budget/schedule-template.test.ts
+++ b/packages/loot-core/src/server/budget/schedule-template.test.ts
@@ -27,7 +27,8 @@ describe('runSchedule', () => {
{
type: 'schedule',
name: 'Test Schedule',
- directive: '#template schedule Test Schedule',
+ priority: 0,
+ directive: 'template',
} as const,
];
const current_month = '2024-08-01';
@@ -97,7 +98,8 @@ describe('runSchedule', () => {
{
type: 'schedule',
name: 'Test Schedule',
- directive: '#template schedule Test Schedule',
+ directive: 'template',
+ priority: 0,
} as const,
];
const current_month = '2024-09-01';
diff --git a/packages/loot-core/src/server/budget/statements.ts b/packages/loot-core/src/server/budget/statements.ts
index b2658578f2..fd5963e6a2 100644
--- a/packages/loot-core/src/server/budget/statements.ts
+++ b/packages/loot-core/src/server/budget/statements.ts
@@ -13,6 +13,7 @@ export async function resetCategoryGoalDefsWithNoTemplates(): Promise<void> {
FROM notes n
WHERE lower(note) LIKE '%${TEMPLATE_PREFIX}%'
OR lower(note) LIKE '%${GOAL_PREFIX}%')
+ AND COALESCE(JSON_EXTRACT(template_settings, '$.source'), 'notes') <> 'ui'
`,
);
}
@@ -37,6 +38,7 @@ export async function getCategoriesWithTemplateNotes(): Promise<
JOIN categories c ON n.id = c.id
WHERE c.id = n.id
AND c.tombstone = 0
+ AND COALESCE(JSON_EXTRACT(c.template_settings, '$.source'), 'notes') <> 'ui'
AND (lower(note) LIKE '%${TEMPLATE_PREFIX}%'
OR lower(note) LIKE '%${GOAL_PREFIX}%')
`,
diff --git a/packages/loot-core/src/server/budget/template-notes.test.ts b/packages/loot-core/src/server/budget/template-notes.test.ts
index b409192410..e568dfda3b 100644
--- a/packages/loot-core/src/server/budget/template-notes.test.ts
+++ b/packages/loot-core/src/server/budget/template-notes.test.ts
@@ -6,7 +6,7 @@ import {
getCategoriesWithTemplateNotes,
resetCategoryGoalDefsWithNoTemplates,
} from './statements';
-import { checkTemplates, storeTemplates } from './template-notes';
+import { checkTemplateNotes, storeNoteTemplates } from './template-notes';
vi.mock('../db');
vi.mock('./statements');
@@ -22,10 +22,10 @@ function mockGetActiveSchedules(schedules: db.DbSchedule[]) {
}
function mockDbUpdate() {
- vi.mocked(db.update).mockResolvedValue(undefined);
+ vi.mocked(db.updateWithSchema).mockResolvedValue(undefined);
}
-describe('storeTemplates', () => {
+describe('storeNoteTemplates', () => {
beforeEach(() => {
vi.clearAllMocks();
});
@@ -131,19 +131,20 @@ describe('storeTemplates', () => {
mockDbUpdate();
// When
- await storeTemplates();
+ await storeNoteTemplates();
// Then
if (expectedTemplates.length === 0) {
- expect(db.update).not.toHaveBeenCalled();
+ expect(db.updateWithSchema).not.toHaveBeenCalled();
expect(resetCategoryGoalDefsWithNoTemplates).toHaveBeenCalled();
return;
}
mockTemplateNotes.forEach(({ id }) => {
- expect(db.update).toHaveBeenCalledWith('categories', {
+ expect(db.updateWithSchema).toHaveBeenCalledWith('categories', {
id,
goal_def: JSON.stringify(expectedTemplates),
+ template_settings: { source: 'notes' },
});
});
expect(resetCategoryGoalDefsWithNoTemplates).toHaveBeenCalled();
@@ -266,7 +267,7 @@ describe('checkTemplates', () => {
mockGetActiveSchedules(mockSchedules);
// When
- const result = await checkTemplates();
+ const result = await checkTemplateNotes();
// Then
expect(result).toEqual(expected);
diff --git a/packages/loot-core/src/server/budget/template-notes.ts b/packages/loot-core/src/server/budget/template-notes.ts
index 90a99c6613..6487ab3e53 100644
--- a/packages/loot-core/src/server/budget/template-notes.ts
+++ b/packages/loot-core/src/server/budget/template-notes.ts
@@ -1,6 +1,6 @@
-import { Template } from '../../types/models/templates';
-import * as db from '../db';
+import type { Template } from '../../types/models/templates';
+import { storeTemplates } from './goal-template';
import { parse } from './goal-template.pegjs';
import {
CategoryWithTemplateNote,
@@ -19,28 +19,21 @@ type Notification = {
export const TEMPLATE_PREFIX = '#template';
export const GOAL_PREFIX = '#goal';
-export async function storeTemplates(): Promise<void> {
+export async function storeNoteTemplates(): Promise<void> {
const categoriesWithTemplates = await getCategoriesWithTemplates();
- for (const { id, templates } of categoriesWithTemplates) {
- const goalDefs = JSON.stringify(templates);
-
- await db.update('categories', {
- id,
- goal_def: goalDefs,
- });
- }
+ await storeTemplates({ categoriesWithTemplates, source: 'notes' });
await resetCategoryGoalDefsWithNoTemplates();
}
-type CategoryWithTemplates = {
+type CategoryWithTemplateNotes = {
id: string;
name: string;
templates: Template[];
};
-export async function checkTemplates(): Promise<Notification> {
+export async function checkTemplateNotes(): Promise<Notification> {
const categoryWithTemplates = await getCategoriesWithTemplates();
const schedules = await getActiveSchedules();
const scheduleNames = schedules.map(({ name }) => name);
@@ -78,8 +71,10 @@ export async function checkTemplates(): Promise<Notification> {
};
}
-async function getCategoriesWithTemplates(): Promise<CategoryWithTemplates[]> {
- const templatesForCategory: CategoryWithTemplates[] = [];
+async function getCategoriesWithTemplates(): Promise<
+ CategoryWithTemplateNotes[]
+> {
+ const templatesForCategory: CategoryWithTemplateNotes[] = [];
const templateNotes = await getCategoriesWithTemplateNotes();
templateNotes.forEach(({ id, name, note }: CategoryWithTemplateNote) => {
diff --git a/packages/loot-core/src/server/db/types/index.ts b/packages/loot-core/src/server/db/types/index.ts
index a8325a1ec3..be6d260d98 100644
--- a/packages/loot-core/src/server/db/types/index.ts
+++ b/packages/loot-core/src/server/db/types/index.ts
@@ -39,6 +39,7 @@ export type DbCategory = {
sort_order: number;
hidden: 1 | 0;
goal_def?: JsonString | null;
+ template_settings?: { source: 'notes' | 'ui' };
tombstone: 1 | 0;
};
diff --git a/packages/loot-core/src/types/models/category.ts b/packages/loot-core/src/types/models/category.ts
index 4e06709db7..5193181401 100644
--- a/packages/loot-core/src/types/models/category.ts
+++ b/packages/loot-core/src/types/models/category.ts
@@ -6,6 +6,7 @@ export interface CategoryEntity {
is_income?: boolean;
group: CategoryGroupEntity['id'];
goal_def?: string;
+ template_settings?: { source: 'notes' | 'ui' };
sort_order?: number;
tombstone?: boolean;
hidden?: boolean;
diff --git a/packages/loot-core/src/types/models/templates.ts b/packages/loot-core/src/types/models/templates.ts
index 76a98582f8..3662de4a2f 100644
--- a/packages/loot-core/src/types/models/templates.ts
+++ b/packages/loot-core/src/types/models/templates.ts
@@ -1,17 +1,20 @@
interface BaseTemplate {
type: string;
- priority?: number;
- directive: string;
+ directive: 'template' | 'goal' | 'error';
+}
+interface BaseTemplateWithPriority extends BaseTemplate {
+ priority: number;
+ directive: 'template';
}
-export interface PercentageTemplate extends BaseTemplate {
+export interface PercentageTemplate extends BaseTemplateWithPriority {
type: 'percentage';
percent: number;
previous: boolean;
category: string;
}
-export interface PeriodicTemplate extends BaseTemplate {
+export interface PeriodicTemplate extends BaseTemplateWithPriority {
type: 'periodic';
amount: number;
period: {
@@ -27,7 +30,7 @@ export interface PeriodicTemplate extends BaseTemplate {
};
}
-export interface ByTemplate extends BaseTemplate {
+export interface ByTemplate extends BaseTemplateWithPriority {
type: 'by';
amount: number;
month: string;
@@ -36,7 +39,7 @@ export interface ByTemplate extends BaseTemplate {
from?: string;
}
-export interface SpendTemplate extends BaseTemplate {
+export interface SpendTemplate extends BaseTemplateWithPriority {
type: 'spend';
amount: number;
month: string;
@@ -45,7 +48,7 @@ export interface SpendTemplate extends BaseTemplate {
repeat?: number;
}
-export interface SimpleTemplate extends BaseTemplate {
+export interface SimpleTemplate extends BaseTemplateWithPriority {
type: 'simple';
monthly?: number;
limit?: {
@@ -56,13 +59,23 @@ export interface SimpleTemplate extends BaseTemplate {
};
}
-export interface ScheduleTemplate extends BaseTemplate {
+export interface ScheduleTemplate extends BaseTemplateWithPriority {
type: 'schedule';
name: string;
full?: boolean;
adjustment?: number;
}
+export interface AverageTemplate extends BaseTemplateWithPriority {
+ type: 'average';
+ numMonths: number;
+}
+
+export interface CopyTemplate extends BaseTemplateWithPriority {
+ type: 'copy';
+ lookBack: number;
+}
+
export interface RemainderTemplate extends BaseTemplate {
type: 'remainder';
weight: number;
@@ -72,27 +85,21 @@ export interface RemainderTemplate extends BaseTemplate {
period?: 'daily' | 'weekly' | 'monthly';
start?: string;
};
-}
-
-export interface AverageTemplate extends BaseTemplate {
- type: 'average';
- numMonths: number;
+ directive: 'template';
+ priority: null;
}
export interface GoalTemplate extends BaseTemplate {
type: 'goal';
amount: number;
-}
-
-export interface CopyTemplate extends BaseTemplate {
- type: 'copy';
- lookBack: number;
+ directive: 'goal';
}
interface ErrorTemplate extends BaseTemplate {
type: 'error';
line: string;
error: string;
+ directive: 'error';
}
export type Template =
diff --git a/upcoming-release-notes/5532.md b/upcoming-release-notes/5532.md
new file mode 100644
index 0000000000..bce0776998
--- /dev/null
+++ b/upcoming-release-notes/5532.md
@@ -0,0 +1,6 @@
+---
+category: Features
+authors: [jfdoming]
+---
+
+Add backend logic to support automations UI