Skip to content

Feature/booking system - #47

Closed
Umeshinduranga wants to merge 7 commits into
mainfrom
feature/booking-system
Closed

Feature/booking system#47
Umeshinduranga wants to merge 7 commits into
mainfrom
feature/booking-system

Conversation

@Umeshinduranga

Copy link
Copy Markdown
Collaborator

This pull request introduces several new features and improvements to the backend of the recovery system, focusing on user registration, counselor management, booking functionality, and data seeding. The changes collectively enhance the API by adding endpoints for booking sessions, managing counselors and their available slots, and supporting user registration for testing. Additionally, a script is provided to seed the database with test counselors and slots.

New Booking and Counselor Features:

  • Added booking controller with endpoints for creating, retrieving, and cancelling bookings, as well as managing counselor slot availability (booking.controller.ts).
  • Introduced endpoints to fetch all counselors with filters and retrieve individual counselor profiles (Counselor.controller.ts).

User Registration and Authentication:

  • Added a custom sign-up endpoint to allow user registration for testing purposes, including basic validation and JWT token generation (auth.controller.ts).
  • Updated API routes to include the new registration and booking endpoints (app.ts). [1] [2] [3]

Data Seeding and Testing:

  • Added a script to seed the database with test counselors, users, and available slots for development and testing (seed-counselors.ts).

API and Code Quality Improvements:

  • Improved response handling in authentication controller methods to ensure consistent return statements (auth.controller.ts). [1] [2]
  • Minor improvements to error handling and Express middleware usage (app.ts).

These changes significantly expand the backend's capabilities for managing counselors, bookings, and user accounts, and provide a solid foundation for testing and further development.

- Fixed Counselor.ts: Changed ref from 'User' to 'users'
- Fixed Booking.ts: Changed ref from 'User' to 'users'
- Fixed Progress.ts: Changed ref from 'User' to 'users'
- Fixed Reminder.ts: Changed ref from 'User' to 'users'
- Fixed Journal.ts: Changed ref from 'User' to 'users'

These fixes ensure proper MongoDB population by using the correct registered model name.
- Modified getBookingById(): First find booking, then check ownership separately
- Returns 403 Forbidden if user doesn't own the booking
- Returns 404 Not Found if booking doesn't exist
- Updated booking controller to handle 403 status code
- Added same access control to cancelBooking()

This ensures proper distinction between 'not found' and 'access denied' scenarios.
- Modified cancelBooking() to fetch booking without populate first
- Checks ownership before attempting cancellation
- Calls markSlotAsAvailable() with raw counselorId string
- Returns populated booking in response for client context
- Improved error handling in slot marking methods
- Enhanced markSlotAsBooked() and markSlotAsAvailable() with try-catch

This ensures slots are properly freed when bookings are cancelled.
- Added custom signUp endpoint for testing (POST /api/auth/register)
- Generates base64-encoded JSON tokens: {id, email, name, role}
- Updated isAuth middleware to support dual auth modes
- Tries BetterAuth sessions first, falls back to base64 tokens
- Decodes and validates base64 tokens against database user
- Registered /api/auth/register route in app.ts

This allows testing without BetterAuth while maintaining production compatibility.
- Added User model import for potential future use
- Fixed specialty filter to use MongoDB  operator
- Specialty filter now correctly matches array elements
- Improved error logging for debugging
- Handles both 'specializations' and 'specialty' query parameters
- Filter supports both single values and comma-separated lists

This ensures specialty filtering works correctly across all counselor queries.
@vercel

vercel Bot commented Mar 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
re-life-website Ignored Ignored Preview Mar 20, 2026 5:40am

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.

3 participants