Skip to content

fixes: Fix Room booking validation bugs in backend#249

Merged
harshitap1305 merged 1 commit intoOpenLake:mainfrom
harshitap1305:backend/roombooking
Apr 11, 2026
Merged

fixes: Fix Room booking validation bugs in backend#249
harshitap1305 merged 1 commit intoOpenLake:mainfrom
harshitap1305:backend/roombooking

Conversation

@harshitap1305
Copy link
Copy Markdown
Member

@harshitap1305 harshitap1305 commented Apr 11, 2026

Bug Fixes:

  • Fixed the "booking must start and end on same day" error by adjusting date boundary calculations to use IST (+5:30) instead of raw UTC.
  • Fixed a 500 Internal Server Error during booking by changing Model.create() to new Model().save() to preserve Mongoose validator context.

Summary by CodeRabbit

  • Bug Fixes

    • Improved timezone accuracy for room booking calculations to correctly handle IST (UTC+5:30) timezone
    • Enhanced booking conflict detection to reliably prevent overlapping reservations with improved error messages
  • Updates

    • Modified the booking interface operating hours to 7:00 AM–11:00 PM for daily operations

Copilot AI review requested due to automatic review settings April 11, 2026 17:16
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 11, 2026

@harshitap1305 is attempting to deploy a commit to the openlake's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 11, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 54ce9ca9-c06a-4a9e-9c1a-52631d0f4cbc

📥 Commits

Reviewing files that changed from the base of the PR and between ff25fd8 and e45dec8.

📒 Files selected for processing (2)
  • backend/controllers/roomBookingController.js
  • frontend/src/Components/RoomBooking.jsx

Walkthrough

The room booking controller was refactored to remove MongoDB transaction/session logic and adjust error handling to return responses directly rather than throw errors. Additionally, date boundary calculations now account for IST timezone offset, and the booking UI timeline was constrained to operate between 07:00 and 23:00 hours instead of the full 24-hour range.

Changes

Cohort / File(s) Summary
Backend Controller Refactoring
backend/controllers/roomBookingController.js
Removed MongoDB transaction/session usage from bookRoom and updateBookingStatus. Updated getDayBounds to compute day boundaries using IST (UTC+5:30) offset. Replaced isSameCalendarDay UTC field comparison with bounds-based checking. Changed error handling patterns from thrown errors to direct response status returns with console.error logging.
Frontend Timeline Range
frontend/src/Components/RoomBooking.jsx
Adjusted booking timeline visible hour window from 00:00–24:00 to 07:00–23:00 by modifying HOUR_START and HOUR_END constants, affecting all downstream timeline calculations and slot-to-position mappings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Hoppy times in IST-land!
No more transactions to demand,
Seven to twenty-three our day,
Bound by bunny-tested way,
Errors logged, responses clear—
The smoothest booking year! ✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@harshitap1305 harshitap1305 merged commit b8c2b52 into OpenLake:main Apr 11, 2026
4 of 7 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to fix room booking validation and booking creation failures in the backend by adjusting day-boundary logic for IST and changing how bookings are persisted, while also removing MongoDB transaction usage for standalone local deployments.

Changes:

  • Adjusted backend date boundary calculations to derive day bounds using IST (+5:30) rather than raw UTC.
  • Reworked booking creation to use new RoomBooking(...).save() and removed transaction/session usage from booking + review flows.
  • Updated frontend booking timeline hour range constants.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
frontend/src/Components/RoomBooking.jsx Changes the selectable timeline window from 00–24 to 07–23.
backend/controllers/roomBookingController.js Updates IST day-boundary logic and rewrites booking / approval endpoints without transactions and with save()-based creation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/controllers/roomBookingController.js
Comment on lines +506 to +517
await Room.updateOne(
{ _id: roomObjectId },
{ $set: { updated_at: new Date() } }
);

const clash = await RoomBooking.findOne({
room: roomObjectId,
status: { $in: ["Pending", "Approved"] },
date: { $gte: dayBounds.dayStart, $lt: dayBounds.dayEnd },
startTime: { $lt: parsedEndTime },
endTime: { $gt: parsedStartTime },
}).select("_id room event startTime endTime status").lean();
Comment on lines +526 to +531
const overlappingEvent = await findOverlappingEvent({
venueCandidates, // removed session
start: parsedStartTime,
end: parsedEndTime,
excludeEventId: eventId,
});
Comment on lines +629 to +634
const overlappingEvent = await findOverlappingEvent({
venueCandidates, // removed session
start: booking.startTime,
end: booking.endTime,
excludeEventId: booking.event,
});
Comment on lines +581 to +590
// --- REMOVED TRANSACTION LOGIC HERE ---

const booking = await RoomBooking.findById(id);
if (!booking) {
return res.status(404).json({ message: "Booking not found" });
}

if (booking.status !== "Pending") {
return res.status(409).json({ message: "Only pending bookings can be reviewed." });
}
Comment on lines +592 to +620
if (status === "Approved") {
if (!(booking.startTime < booking.endTime)) {
return res.status(400).json({ message: "Invalid booking time range for approval." });
}

await Room.updateOne(
{ _id: booking.room },
{ $set: { updated_at: new Date() } }
);

const roomForBooking = await Room.findById(booking.room)
.select("name room_id location")
.lean();

if (!roomForBooking) {
return res.status(404).json({ message: "Room not found or inactive." });
}

const venueCandidates = getRoomVenueCandidates(roomForBooking);
const dayBounds = getDayBounds(booking.date);

const overlappingApprovedBooking = await RoomBooking.findOne({
_id: { $ne: booking._id },
room: booking.room,
status: "Approved",
date: { $gte: dayBounds.dayStart, $lt: dayBounds.dayEnd },
startTime: { $lt: booking.endTime },
endTime: { $gt: booking.startTime },
}).select("_id room event startTime endTime").lean();
Comment thread frontend/src/Components/RoomBooking.jsx
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.

2 participants