DEV Community

Susheel kumar
Susheel kumar

Posted on

Budget handling using npm package saksh-wallet

Budget Management

Set Budget:

• Users can set budgets for specific categories and periods (daily, weekly, monthly).

• The system checks for overlapping budgets to prevent multiple budgets for the same category and period.

Adjust Budget:
• Users can adjust their existing budgets.

• The system maintains a history of budget adjustments.

Check Budget:
• The system checks if a new transaction will exceed the user's budget for a specific category and period.

• If the budget is exceeded, an error is thrown, and the transaction is prevented.

Get Budget Status:
• Users can retrieve the status of their budgets, including total budget, total spent, and available budget.

• The status includes details such as category, period, start date, and end date.

Enable/Disable Budget:
• Users can enable or disable budget checks.

• When the budget is disabled, transactions are not checked against the budget limits.

Event Emission:
• The system emits a budgetExceeded event when a budget is exceeded, providing details such as user ID, category, amount spent, and budget amount.

Example Usage


const SakshBudgetManagement = require('./SakshBudgetManagement');
const budgetManagement = new SakshBudgetManagement();

// Set a budget
await budgetManagement.sakshSetBudget(userId, 'groceries', 5000, 'monthly');

// Adjust a budget
await budgetManagement.sakshAdjustBudget(userId, 'groceries', 6000);

// Check budget before a transaction
await budgetManagement.sakshCheckBudget(userId, 'groceries', 1000);

// Get budget status
const status = await budgetManagement.sakshGetBudgetStatus(userId, 'groceries');
console.log(status);

// Enable or disable budget
await budgetManagement.sakshToggleBudget(userId, true); // Enable budget
await budgetManagement.sakshToggleBudget(userId, false); // Disable budget

Enter fullscreen mode Exit fullscreen mode

Here is the full code which used you can review the code from https://www.npmjs.com/package/saksh-wallet and suggest

or contact at susheel2339@gmail.com

Top comments (0)