Problem
Controllers and services lack consistent input validation. While the Photo module (src/modules/photo/presentation/controllers/PhotoController.ts) uses express-validator, most endpoints accept raw request bodies without validation, including:
createVolunteer in src/controllers/VolunteerController.ts
createProject in src/controllers/Project.controller.ts
- Auth endpoints (register/login)
This creates risk of:
- Invalid data types persisting to the database (e.g.,
parseInt(userId, 10) in PhotoController.ts:51 without prior validation).
- Missing required fields not caught until the service/repository layer.
- Date parsing issues (
new Date(startDate) in the project controller without format validation).
- Inconsistent error responses for validation failures across modules.
express-validator and class-validator are already installed but underutilized.
Proposed Solution
- Create a reusable
ValidationPipe middleware in src/middleware/ that wraps express-validator chains and returns a standardized 400 response.
- Define DTOs/validation schemas using
class-validator decorators in src/dtos/ (or co-located with each module): CreateProjectDTO, CreateVolunteerDTO, RegisterUserDTO, LoginDTO, UploadPhotoDTO.
- Apply the validation middleware consistently across auth, project, volunteer, user, and photo routes.
- Standardize the validation error response format with field-level error details.
- Add
tests/validation.test.ts covering positive and negative cases for at least 5 critical endpoints.
Acceptance Criteria
Out of Scope
- Refactoring existing service-layer validation (separate effort).
- Changing the auth strategy or JWT logic.
Suggested Labels
enhancement, code-quality, testing
Problem
Controllers and services lack consistent input validation. While the Photo module (
src/modules/photo/presentation/controllers/PhotoController.ts) usesexpress-validator, most endpoints accept raw request bodies without validation, including:createVolunteerinsrc/controllers/VolunteerController.tscreateProjectinsrc/controllers/Project.controller.tsThis creates risk of:
parseInt(userId, 10)inPhotoController.ts:51without prior validation).new Date(startDate)in the project controller without format validation).express-validatorandclass-validatorare already installed but underutilized.Proposed Solution
ValidationPipemiddleware insrc/middleware/that wrapsexpress-validatorchains and returns a standardized 400 response.class-validatordecorators insrc/dtos/(or co-located with each module):CreateProjectDTO,CreateVolunteerDTO,RegisterUserDTO,LoginDTO,UploadPhotoDTO.tests/validation.test.tscovering positive and negative cases for at least 5 critical endpoints.Acceptance Criteria
Out of Scope
Suggested Labels
enhancement,code-quality,testing