Skip to content

fix: optimize amenity controller for readability and consistency#25

Open
1234-ad wants to merge 1 commit intoguptapratykshh:branch1from
1234-ad:fix/optimize-amenity-controller
Open

fix: optimize amenity controller for readability and consistency#25
1234-ad wants to merge 1 commit intoguptapratykshh:branch1from
1234-ad:fix/optimize-amenity-controller

Conversation

@1234-ad
Copy link

@1234-ad 1234-ad commented Nov 5, 2025

🎯 Resolves Issue

Closes #20

📝 Changes Made

Code Quality Improvements

  • Standardized Response Handlers: Added handleError() and handleSuccess() helper functions for consistent API responses
  • Constants for Validation: Introduced BOOKING_STATUS and VALID_STATUSES constants to eliminate magic strings
  • Comprehensive JSDoc Comments: Added detailed documentation for all functions including route, access level, and parameters
  • Consistent Error Handling: Unified error handling pattern across all controller methods
  • Success/Failure Flags: All responses now include success boolean flag for easier client-side handling

Performance Optimizations

  • Parallel Operations: Used Promise.all() in deleteAmenity() to delete bookings and amenity simultaneously
  • Validation Enhancement: Added runValidators: true option to findByIdAndUpdate() for data integrity

Developer Experience

  • 📚 Better Error Messages: More descriptive error responses with valid options included
  • 📚 Development Mode Details: Error details exposed in development environment for easier debugging
  • 📚 Code Organization: Improved structure with constants and helper functions at the top

🔍 Code Comparison

Before: Repetitive error handling, inconsistent responses, no documentation
After: DRY principles, standardized responses, comprehensive documentation

✅ Testing Checklist

  • All existing functionality preserved
  • Response format remains backward compatible (data wrapped in data field)
  • Error handling improved without breaking changes
  • Status validation enhanced with clear error messages

📸 Benefits

  • Easier maintenance and debugging
  • Consistent API response structure
  • Better code readability
  • Improved error handling
  • Enhanced developer experience

- Add standardized response handlers (handleError, handleSuccess)
- Introduce constants for booking status validation
- Add comprehensive JSDoc comments for all functions
- Implement consistent error handling across all methods
- Add success/failure flags in responses
- Use Promise.all for parallel operations in deleteAmenity
- Add runValidators option to findByIdAndUpdate
- Include valid status options in error responses
- Improve code organization and maintainability

Resolves guptapratykshh#20
@vercel
Copy link

vercel bot commented Nov 5, 2025

@1234-ad is attempting to deploy a commit to the pg999999's projects Team on Vercel.

A member of the Team first needs to authorize it.

@netlify
Copy link

netlify bot commented Nov 5, 2025

Deploy Preview for gatednet canceled.

Name Link
🔨 Latest commit d1bbb4c
🔍 Latest deploy log https://app.netlify.com/projects/gatednet/deploys/690aeecc75f9ac0008243005

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue: Optimize Amenity Controller for Readability and Consistency

1 participant