Skip to content

Add budget overspend alert notification (#74)#107

Merged
Uyoxy merged 1 commit into
stellarspend:mainfrom
mimijuwonlo-commits:budget-overspend-alert-notification
Jun 24, 2026
Merged

Add budget overspend alert notification (#74)#107
Uyoxy merged 1 commit into
stellarspend:mainfrom
mimijuwonlo-commits:budget-overspend-alert-notification

Conversation

@mimijuwonlo-commits

Copy link
Copy Markdown

This PR implements budget overspend notifications that alert users when they approach or exceed their budget limits. Previously, the budgets service did not send any notifications when a user exceeded or was close to their budget limits.

Now, whenever budgets are queried or updated, the system checks the current spending (summing completed transactions within the budget category, asset, and date range) and triggers notifications via NotificationsService at two key thresholds:

80% Budget Usage (Warning)
100% Budget Usage (Error/Limit Exceeded)
To prevent duplicate alerts, the system checks the database to verify if a notification has already been created for that specific threshold and budget ID.

Proposed Changes
Notifications Module
src/modules/notifications/notifications.service.ts:
Added findOneByCategory(userId, category) to check if a specific threshold notification already exists for the budget.
Added createBudgetAlertNotification(userId, budgetId, categoryName, limit, usagePercent) to create template-based alert notifications for 80% and 100% usage thresholds.
Budgets Module
src/modules/budgets/budgets.module.ts:
Imported TypeOrmModule.forFeature([Transaction]) and NotificationsModule to inject dependencies into BudgetsService.
src/modules/budgets/budgets.service.ts:
Modified the constructor to accept optional notificationsService and transactionRepository parameters. Using optional dependencies keeps compatibility with existing unit tests.
Implemented checkAndTriggerOverspendAlerts(budget) to calculate the total spent amount for a budget's active period and category, triggering notifications if the 80% or 100% thresholds are met.
Integrated the overspend alert check into the findById, findByUserId, create, and update methods.
Tests
src/modules/budgets/budgets.service.spec.ts:
Added unit test cases to verify the overspend check triggers correctly at 80% and 100% usage, avoids duplicate notifications on repeated checks, and runs safely without throwing when dependencies are not present.
Verification & Testing
Automated Tests
Ran the unit tests for the budgets service, and all 105 tests passed successfully:

bash

npx jest src/modules/budgets/budgets.service.spec.ts
Output:

Test Suites: 1 passed, 1 total
Tests: 105 passed, 105 total
Snapshots: 0 total
Time: 5.345 s
Linting
Verified that all modified files comply with the codebase's strict lint rules:

bash

npm run lint
Output:

Zero linting errors or warnings in the modified files.

close #74

@Uyoxy Uyoxy merged commit 2dc3ca7 into stellarspend:main Jun 24, 2026
0 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Title: Add budget overspend alert notification

3 participants