Pull Request: Implement Comprehensive Input Validation (#117)#171
Merged
LaGodxy merged 2 commits intoMar 26, 2026
Merged
Conversation
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.
📝 Description
This PR addresses the lack of input validation across our API endpoints. By implementing strict DTO (Data Transfer Object) validation, we ensure that all incoming requests are sanitized and conform to our expected data types and business constraints before reaching the service layer.
🎯 Key Changes
Global Validation Pipe: Integrated a global ValidationPipe to automatically intercept and validate all incoming requests.
Declarative DTOs: Enhanced existing DTOs with class-validator decorators (e.g., @IsString(), @isemail(), @min(0)).
Custom Business Validators: Created a custom decorator to validate PropChain-specific logic, such as ensuring property ownership IDs match the required format.
Error Formatting: Implemented a standardized error response structure so the frontend receives clear, actionable feedback when a field fails validation.
💻 Implementation Snippet (NestJS/DTO)
Example of the new validation rules applied to a property listing:
TypeScript
import { IsString, IsNumber, Min, IsEnum, IsNotEmpty } from 'class-validator';
export class CreatePropertyDto {
@IsString()
@isnotempty()
title: string;
@IsNumber()
@min(1000) // Minimum investment threshold
price: number;
@IsEnum(['Residential', 'Commercial', 'Industrial'])
propertyType: string;
}
✅ Acceptance Criteria Checklist
[x] Comprehensive Validation: All major DTOs (Auth, Property, Investment) now have type and constraint checks.
[x] Custom Rules: Implemented a validator for checking blockchain address formats.
[x] Graceful Error Handling: API now returns 400 Bad Request with a detailed message array instead of internal server errors.
[x] Stripping Non-Whitelisted Properties: Configured the pipe to strip any properties not explicitly defined in the DTO (prevents mass-assignment vulnerabilities).
🚀 How to Verify
Start the Server: npm run start:dev
Trigger a Validation Failure: Send a POST request to /properties with an empty title or negative price.
Confirm Response: Verify the API returns a structured error like:
JSON
{
"statusCode": 400,
"message": ["price must not be less than 1000"],
"error": "Bad Request"
}
🔗 Linked Issues
Closes #117