fixes: Fix Room booking validation bugs in backend#249
fixes: Fix Room booking validation bugs in backend#249harshitap1305 merged 1 commit intoOpenLake:mainfrom
Conversation
|
@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. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThe 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.
| 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(); |
| const overlappingEvent = await findOverlappingEvent({ | ||
| venueCandidates, // removed session | ||
| start: parsedStartTime, | ||
| end: parsedEndTime, | ||
| excludeEventId: eventId, | ||
| }); |
| const overlappingEvent = await findOverlappingEvent({ | ||
| venueCandidates, // removed session | ||
| start: booking.startTime, | ||
| end: booking.endTime, | ||
| excludeEventId: booking.event, | ||
| }); |
| // --- 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." }); | ||
| } |
| 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(); |
Bug Fixes:
Model.create()tonew Model().save()to preserve Mongoose validator context.Summary by CodeRabbit
Bug Fixes
Updates