Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Reset Hold and Hold For Next Month api #3140

8 changes: 8 additions & 0 deletions packages/api/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/hold-budget-for-next-month', { month, amount });
}

export function resetBudgetHold(month) {
return send('api/reset-budget-hold', { month });
}
21 changes: 21 additions & 0 deletions packages/loot-core/src/server/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,27 @@ handlers['api/budget-set-carryover'] = withMutation(async function ({
});
});

handlers['api/hold-budget-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/reset-budget-hold'] = withMutation(async function ({ month }) {
checkFileOpen();
await validateMonth(month);
return handlers['budget/reset-hold']({ month });
});

handlers['api/transactions-export'] = async function ({
transactions,
categoryGroups,
Expand Down
7 changes: 7 additions & 0 deletions packages/loot-core/src/types/api-handlers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ export interface ApiHandlers {
flag: boolean;
}) => Promise<void>;

'api/hold-budget-for-next-month': (arg: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thought I had is it might be good to call this budget-hold-for-next-month (and use the same pattern for the other endpoint) vs the current hold-budget-for-next-month. My thought process is that the former sounds more like you're holding an amount from the budget for next month (the additive nature of the feature), whereas the latter is holding the entire budget. Doing the former also matches previous endpoints in the file (e.g. budget-set-amount, budget-set-carryover)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Changing it

month: string;
amount: number;
}) => Promise<void>;

'api/reset-budget-hold': (arg: { month: string }) => Promise<void>;

'api/transactions-export': (arg: {
transactions;
categoryGroups;
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3140.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [rodriguestiago0]
---

Add `reset-hold` and `hold-for-next-month` methods to the API
Loading