As a developer, I need to create a middleware function to validate the request body when creating a new "Need" item, ensuring that the request contains the required fields: title, description, and zip code. This validation middleware will help maintain data integrity and consistency within the application.
Acceptance Criteria
Define a middleware function to validate the request body when creating a new "Need" item.
Implement validation logic to ensure the request body contains the following fields: title, description, and zip code.
Validate that each field is present in the request body and is not empty or null.
Implement additional validation rules as necessary (e.g., length restrictions, data type validation).
Return an error response with the appropriate status code and message if the request body fails validation.
Integrate the validation middleware into the route handler for creating "Need" items.
Test the validation middleware thoroughly with both valid and invalid request payloads.
Ensure error messages provide clear guidance on missing or invalid fields to aid frontend development and debugging.
Document the validation middleware function, including its purpose, input requirements, and usage guidelines.
Ensure the validation middleware is properly integrated and functioning in the backend application.
Coordinate with the frontend team to ensure consistent handling of validation errors on the client side.
Testing
Use Postman to send a POST request containing the "Need" data needed to create a new "Need" document.
Omit the title, description, or the zip to ensure the middleware rejects the request with a 400 bad data.
Ensure the middleware passes the request to the controller if the fields are present and correct.
Description
As a developer, I need to create a middleware function to validate the request body when creating a new "Need" item, ensuring that the request contains the required fields: title, description, and zip code. This validation middleware will help maintain data integrity and consistency within the application.
Acceptance Criteria
Testing