Friendsofthepeople / recall-server

A Node server for managing the verification of constituents, publishing of representative information, and signing to recall them.
MIT License
22 stars 6 forks source link

Added Zod Schema Validation and Error Handling #8

Closed Gabriel-Mbugua closed 6 days ago

Gabriel-Mbugua commented 1 week ago

This PR introduces Zod schema validation and error handling to the project. This is to address issue #4.

1. Zod Schema Validation:

2: Zod Error Handling:

Changes Made

### 1:Middleware:

        - middleware/validate.ts: Middleware to validate request bodies using Zod schemas.
        - middleware/zodErrorHandler.ts: Middleware to handle errors thrown by Zod validation.

### 2: Validation:
        - validation/user.validate.ts: Schema for validating user registration data.
        - validation/recall.validate.ts: Schema for validating recall petition data.
        - validation/index.ts: Export file for all schemas.

### 3: Routes:

        - routes/user.route.ts: Applied Zod validation and error handling for user registration.

Request for Review

Please review the changes to ensure they align with our project's best practices. Specifically, I'd appreciate feedback on:

  1. Schema Definitions: Are the Zod schemas comprehensive and correct?
  2. Middleware Logic: Is the separation of validation and error handling logic appropriate?
  3. Error Handling: Does the approach to error handling maintain clarity and consistency?
  4. Best Practices: Are there any areas where we can improve or align better with our coding standards?

Looking forward to your feedback and suggestions for any improvements.

Thank you!

Gabriel-Mbugua commented 6 days ago

Updated Changes: Refactor User Module and Common Middlewares

In addition to the previous changes, this update includes:

Recent Changes

Reasoning for Changes

These changes were made to improve code organization, reusability, and maintainability. By incorporating registration into the auth module, we've kept related functionality together. Moving common middlewares to a shared package allows for easier reuse across different parts of the application.

Impact on Docker Instances

The changes should not significantly impact the Docker setup. However, the Docker containers should be rebuilt and tested on the staging server to ensure compatibility.

Testing Done

Please review these additional changes and let me know if any further modifications are needed.