diff --git a/packages/api/methods.ts b/packages/api/methods.ts index 06109bf8374..fc345506352 100644 --- a/packages/api/methods.ts +++ b/packages/api/methods.ts @@ -208,3 +208,11 @@ export function updateRule(rule) { export function deleteRule(id) { return send('api/rule-delete', { id }); } + +export function holdBudgetForNextMonth(month, amount) { + return send('api/budget-hold-for-next-month', { month, amount }); +} + +export function resetBudgetHold(month) { + return send('api/budget-reset-hold', { month }); +} diff --git a/packages/loot-core/src/server/api.ts b/packages/loot-core/src/server/api.ts index 84e53840501..6d49fb81316 100644 --- a/packages/loot-core/src/server/api.ts +++ b/packages/loot-core/src/server/api.ts @@ -406,6 +406,27 @@ handlers['api/budget-set-carryover'] = withMutation(async function ({ }); }); +handlers['api/budget-hold-for-next-month'] = withMutation(async function ({ + month, + amount, +}) { + checkFileOpen(); + await validateMonth(month); + if (amount <= 0) { + throw APIError('Amount to hold needs to be greater than 0'); + } + return handlers['budget/hold-for-next-month']({ + month, + amount, + }); +}); + +handlers['api/budget-reset-hold'] = withMutation(async function ({ month }) { + checkFileOpen(); + await validateMonth(month); + return handlers['budget/reset-hold']({ month }); +}); + handlers['api/transactions-export'] = async function ({ transactions, categoryGroups, diff --git a/packages/loot-core/src/types/api-handlers.d.ts b/packages/loot-core/src/types/api-handlers.d.ts index 2b9bd088081..cf26bac83ab 100644 --- a/packages/loot-core/src/types/api-handlers.d.ts +++ b/packages/loot-core/src/types/api-handlers.d.ts @@ -63,6 +63,13 @@ export interface ApiHandlers { flag: boolean; }) => Promise; + 'api/budget-hold-for-next-month': (arg: { + month: string; + amount: number; + }) => Promise; + + 'api/budget-reset-hold': (arg: { month: string }) => Promise; + 'api/transactions-export': (arg: { transactions; categoryGroups; diff --git a/upcoming-release-notes/3140.md b/upcoming-release-notes/3140.md new file mode 100644 index 00000000000..0802097b93c --- /dev/null +++ b/upcoming-release-notes/3140.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [rodriguestiago0] +--- + +Add `reset-hold` and `hold-for-next-month` methods to the API \ No newline at end of file