Align Module — Isolate Guards, DTOs, and Error Handling#87
Open
SheyeJDev wants to merge 1 commit into
Open
Conversation
Contributor
|
@SheyeJDev Please check and fix |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor Portfolio Module for Domain Encapsulation, Validation, and Error Handling
Overview
This PR refactors the Portfolio module to improve domain ownership, reduce duplication, strengthen validation, and introduce portfolio-specific error handling.
The Portfolio module is one of the most complex domains in the application, containing multiple entities, services, DTOs, optimization algorithms, and ML-driven portfolio management logic. Prior to this change, portfolio concerns were partially scattered across the application, with entities registered globally, duplicate guard implementations, and generic exception handling for financial operations.
This refactor aligns the module with NestJS modular architecture principles by making Portfolio responsible for its own entities, validation, and domain-specific behaviors.
Changes Made
1. Portfolio Entity Encapsulation
Moved portfolio entity registration from the global application configuration into the Portfolio module.
Before
app.module.ts.After
TypeOrmModule.forFeature([...portfolioEntities])toPortfolioModule.Benefits
2. Guard Consolidation
Reviewed all guards located in:
Actions Taken
Benefits
3. Domain-Specific Exception Handling
Introduced portfolio-specific exception classes for financial and optimization workflows.
New Exceptions
Examples:
InsufficientBalanceExceptionOptimizationFailedExceptionRebalancingFailedExceptionUsage
Portfolio services now throw explicit domain exceptions instead of generic NestJS or JavaScript errors when:
Benefits
4. DTO Validation Improvements
Reviewed all Portfolio DTOs and ensured validation rules are explicitly defined using
class-validator.Validation Enhancements
Added appropriate decorators where applicable:
Validation Flow
ValidationPipe.Benefits
Architectural Improvements
This PR moves the Portfolio domain closer to a true bounded-context architecture by ensuring it owns:
while relying only on shared infrastructure provided by the common module.
Files/Areas Updated
Portfolio Module
src/investment/portfolio/portfolio.module.tsApp Module
src/app.module.tsGuards
src/investment/portfolio/guards/*(removed)src/common/guard/*(updated)Exceptions
src/investment/portfolio/exceptions/*DTOs
src/investment/portfolio/dto/*Services
Validation Performed
TypeOrmModule.forFeature().ValidationPipe.Acceptance Criteria Checklist
TypeOrmModule.forFeature()for all portfolio entitiesapp.module.tscommon/guard/src/investment/portfolio/guards/removedclass-validatordecoratorsnpm run buildsucceedsCloses #10