checkIn
Performs the check-in process for a confirmed reservation, updating reservation status and room occupation.Function Signature
Parameters
The hotel object containing the reservation
The unique ID of the reservation to check in
Validations
The function performs the following validations in order:- Reservation Exists: Checks if the reservation ID exists (main.js:174-176)
- Status is Confirmed: Verifies reservation status is
'confirmed'(main.js:177-179) - Valid Check-In Date: Check-in date must be today or in the past using
isDateTodayOrPast()(main.js:180-182, validation.js:24-27) - Room Available: The room status must be
'available', not'occupied'(main.js:186-188)
Status Changes
When check-in is successful:- Reservation Status: Changed from
'confirmed'to'checked_in'(main.js:190) - Room Status: Changed from
'available'to'occupied'(main.js:191) - Check-In Date: Updated to current date using
Temporal.Now.plainDateISO()(main.js:192)
Return Value
Returns a success message or error description
Example
Expected Output
State Changes Visualization
The actual check-in date is recorded when the function executes, which may differ from the originally planned check-in date in the reservation.
checkOut
Performs the check-out process, generates an invoice, releases the room, and archives the reservation.Function Signature
Parameters
The hotel object containing the reservation
The unique ID of the reservation to check out
Validations
- Reservation Exists: Verifies the reservation ID exists (main.js:201-203)
- Status is Checked-In: Must be
'checked_in'status (main.js:204-206) - Valid Check-Out Date: Check-out date must be on or after check-in date using
isEndDateOnOrAfterStartDate()(main.js:207-209)
Process Flow
When check-out is successful:- Update Reservation Status: Changed to
'checked_out'(main.js:211) - Release Room: Room status changed to
'available'(main.js:212) - Archive Reservation: Moves reservation from
hotel.reservationstohotel.history(main.js:214, utils.js:142-146) - Generate Invoice: Creates detailed invoice object (main.js:216, utils.js:160-181)
Return Value
Returns a detailed invoice object if successful, or an error string if validation fails
Error Cases
"La reserva no existe, no se puede realizar el check-out"- Reservation not found"No se hizo el check-in de la reserva. Status: {status}"- Not checked in"La fecha de check-out no es válida"- Check-out before check-in
Example
Expected Output
cancelReservation
Cancels a reservation with penalty calculation based on cancellation policy, then archives it.Function Signature
Parameters
The hotel object containing the reservation
The unique ID of the reservation to cancel
Cancellation Policy
The penalty is calculated based on days until check-in (utils.js:186-202):Process Flow
- Find Reservation: Retrieves reservation by ID (main.js:223)
- Calculate Penalty: Calls
getCancellationCharge()to determine penalty (main.js:224, utils.js:186-202) - Validate Exists: Checks if reservation exists (main.js:225-227)
- Get Room: Retrieves the room object (main.js:229)
- Update Status: Sets reservation status to
'cancelled'(main.js:231) - Release Room: Sets room status to
'available'(main.js:232) - Archive: Moves reservation to history (main.js:233)
- Return Message: Includes penalty amount (main.js:235)
Return Value
Returns a cancellation confirmation message with penalty amount
Example
Penalty Calculation Example
The cancellation policy uses
Temporal.Now.plainDateISO() to calculate days until check-in, ensuring accurate timezone-independent date calculations.Related Functions
getCancellationCharge()- Calculates penalty amount (utils.js:186-202)archiveReservation()- Moves to history (utils.js:142-146)getReservationById()- Finds reservation (utils.js:132-137)getRoomByNumber()- Gets room object (utils.js:18-21)