- Renamed `getErrorMessage` to `extractErrorMessage` for clarity and to avoid confusion with the domain's `getMessageForErrorCode`. - Introduced a deprecation notice for `getErrorMessage` to maintain backward compatibility. - Updated various services and controllers to utilize the new `extractErrorMessage` function, ensuring consistent error handling across the application. - Enhanced error handling in the `BillingController`, `SubscriptionsService`, and other modules to improve maintainability and clarity in API responses.
6.1 KiB
6.1 KiB
Code Quality Improvement Checklist
Use this checklist to track progress on the refactoring plan.
Phase 1: Quick Wins ✅ COMPLETE
1.1 Add Mapping Helper Methods ✅
- Add
getWhmcsClientIdOrThrow()toMappingsService - Add
getMappingOrThrow()toMappingsService - Add unit tests for new methods
- Update
index.tsexports if needed (N/A - no index.ts)
1.2 Refactor WHMCS Mapping Lookups ✅
apps/bff/src/modules/billing/billing.controller.ts(4 occurrences)apps/bff/src/modules/billing/services/invoice-retrieval.service.ts(1 occurrence)- Remove private
getUserMapping()method
- Remove private
apps/bff/src/modules/users/infra/user-profile.service.ts(2 occurrences)apps/bff/src/modules/subscriptions/subscriptions.service.ts(3 occurrences)apps/bff/src/modules/subscriptions/sim-management/services/esim-management.service.ts(1 occurrence)apps/bff/src/modules/subscriptions/sim-management/services/sim-cancellation.service.ts(2 occurrences)apps/bff/src/modules/subscriptions/sim-management/services/sim-topup.service.ts(1 occurrence)apps/bff/src/modules/subscriptions/sim-order-activation.service.ts(1 occurrence)apps/bff/src/modules/auth/application/auth.facade.ts(1 occurrence)- Run tests after each file change
1.3 Rename getErrorMessage Functions ✅
Step 1: Add new function names as aliases
- In
apps/bff/src/core/utils/error.util.ts: AddextractErrorMessageas alias - In
packages/domain/common/errors.ts: AddgetMessageForErrorCodeas alias - Update exports in both locations
Step 2: Update all imports (gradual migration)
- Old names kept as deprecated aliases for backwards compatibility
- Update imports incrementally (can be done over time)
Step 3: Remove old function names
- Remove
getErrorMessagefromerror.util.ts(after migration complete) - Remove
getErrorMessagefromerrors.ts(after migration complete) - Run full test suite
1.4 Remove Unused Status Wrapper Methods ✅
Audit usage:
invoice-retrieval.service.ts→getUnpaidInvoices()- UNUSED, REMOVEDinvoice-retrieval.service.ts→getOverdueInvoices()- UNUSED, REMOVEDinvoice-retrieval.service.ts→getPaidInvoices()- UNUSED, REMOVEDinvoice-retrieval.service.ts→getCancelledInvoices()- UNUSED, REMOVEDinvoice-retrieval.service.ts→getCollectionsInvoices()- UNUSED, REMOVEDinvoice-retrieval.service.ts→hasInvoices()- UNUSED, REMOVEDinvoice-retrieval.service.ts→getInvoiceCountByStatus()- UNUSED, REMOVEDsubscriptions.service.ts→getSuspendedSubscriptions()- UNUSED, REMOVEDsubscriptions.service.ts→getCancelledSubscriptions()- UNUSED, REMOVEDsubscriptions.service.ts→getPendingSubscriptions()- UNUSED, REMOVED
Phase 2: Medium-Term Improvements ✅ COMPLETE
2.1 Create Error Handling Utility ✅
- Create
apps/bff/src/core/utils/error-handler.util.ts - Add
withErrorHandling()function - Add
withErrorSuppression()function - Add
withErrorLogging()function - Add unit tests
- Export from
apps/bff/src/core/utils/index.ts(optional)
2.2 Refactor Services to Use Error Handling Utility (Partial) ✅
High Priority:
invoice-retrieval.service.ts- Refactored to usewithErrorHandling
Medium Priority (not yet done):
subscriptions.service.ts(12 blocks)user-profile.service.ts(6 blocks)signup-workflow.service.ts(8 blocks)password-workflow.service.ts(4 blocks)whmcs-link-workflow.service.ts(5 blocks)
2.3 Consolidate WHMCS Connection Methods ✅
- Update
WhmcsRequestOptionsinterface withhighPriorityoption - Refactor
makeRequest()to handle both cases - Deprecate
makeHighPriorityRequest()(don't remove yet) - Update callers of
makeHighPriorityRequest()(not required, deprecated method delegates) - Run integration tests
Phase 3: Long-Term Improvements (Partial)
3.1 Split SignupWorkflowService ✅
Create new files:
signup.types.tssignup-validation.service.tssignup-account-resolver.service.tsindex.ts(exports)
Migration:
- Move validation logic to
signup-validation.service.ts - Move account resolution to
signup-account-resolver.service.ts - Refactor
signup-workflow.service.tsto use new services - Update
auth.module.tswith new providers - Update tests
- Keep
signup-workflow.service.tsas orchestrator (delegating to new services)
3.2 Split UserProfileService (DEFERRED)
Create new files:
dashboard.service.tswhmcs-custom-fields.util.ts
Migration:
- Extract
getUserSummary()toDashboardService - Extract custom field logic to utility
- Update module providers
- Update tests
3.3 Evaluate WhmcsService Facade (DEFERRED)
Analysis:
- List all direct usages of
WhmcsService - Determine if cross-cutting concerns are needed
- Make go/no-go decision
3.4 Dead Code Audit (DEFERRED)
Tools:
- Run
ts-pruneto find unused exports - Review test coverage reports
3.5 Create LoggableService Base Class (DEFERRED - Optional)
- Team decision on using inheritance
- If yes: Create base class
- If yes: Migrate services incrementally
Final Verification
- All unit tests passing
- All integration tests passing
- Manual smoke testing complete
- No new linter errors (verified with TypeScript compiler)
- Documentation updated
- PR reviewed and approved
Notes
| Date | Note |
|---|---|
| Dec 2025 | Phase 1 and Phase 2 completed. Phase 3.1 (SignupWorkflowService split) completed. Remaining Phase 3 items deferred for future sprints. |