chore: Integrate confirmation booking audit#26
Conversation
| updatedBookings.push(updatedBooking); | ||
| acceptedBookings = [ | ||
| { | ||
| oldStatus: BookingStatus.ACCEPTED, |
There was a problem hiding this comment.
🔴 Incorrect oldStatus hardcoded as ACCEPTED instead of using booking.status
In the non-recurring booking acceptance flow, the oldStatus is incorrectly hardcoded to BookingStatus.ACCEPTED instead of using the actual booking.status value.
Click to expand
How the bug occurs
When a single (non-recurring) booking is accepted via handleConfirmation(), the code builds the acceptedBookings array to fire the audit event:
acceptedBookings = [
{
oldStatus: BookingStatus.ACCEPTED, // BUG: Should be booking.status
uid: booking.uid,
},
];The booking.status field is available in the function arguments (see packages/features/bookings/lib/handleConfirmation.ts:126) and should be BookingStatus.PENDING for bookings awaiting confirmation.
Actual vs Expected
- Actual: Audit log records
oldStatus: ACCEPTEDandnewStatus: ACCEPTED(no change detected) - Expected: Audit log should record
oldStatus: PENDINGandnewStatus: ACCEPTED(showing the actual status transition)
Impact
The booking audit trail will have incorrect data, making it impossible to track the actual status transition from PENDING to ACCEPTED for non-recurring bookings.
Recommendation: Change oldStatus: BookingStatus.ACCEPTED to oldStatus: booking.status
Was this helpful? React with 👍 or 👎 to provide feedback.
| rejectedBookings = updatedRecurringBookings.map((recurringBooking) => ({ | ||
| uid: recurringBooking.uid, | ||
| oldStatus: recurringBooking.status, | ||
| })); |
There was a problem hiding this comment.
🔴 Rejection audit uses post-update status as oldStatus for recurring bookings
In the rejection flow for recurring bookings, the code fetches bookings AFTER they've been updated, causing the audit to record the NEW status (REJECTED) as the old status.
Click to expand
How the bug occurs
The code flow is:
- Fetch
unconfirmedRecurringBookingswithstatus: BookingStatus.PENDING(line 409-418) - Update all bookings to
status: BookingStatus.REJECTED(line 420-430) - Fetch the same bookings AGAIN as
updatedRecurringBookings(line 432-442) - Use the status from
updatedRecurringBookingsasoldStatus(line 444-446)
rejectedBookings = updatedRecurringBookings.map((recurringBooking) => ({
uid: recurringBooking.uid,
oldStatus: recurringBooking.status, // BUG: This is now REJECTED, not PENDING
}));Actual vs Expected
- Actual: Audit log records
oldStatus: REJECTEDandnewStatus: REJECTED - Expected: Audit log should record
oldStatus: PENDINGandnewStatus: REJECTED
Impact
The booking audit trail for recurring booking rejections will incorrectly show no status change, making it impossible to track the actual transition from PENDING to REJECTED.
Recommendation: Use unconfirmedRecurringBookings (which contains the pre-update status) instead of updatedRecurringBookings. Change to: rejectedBookings = unconfirmedRecurringBookings.map((booking) => ({ uid: booking.uid, oldStatus: booking.status }));
Was this helpful? React with 👍 or 👎 to provide feedback.
Benchmark PR from qodo-benchmark#714