Reservation Management
createUniqueReservationId()
Generates a unique reservation ID using a timestamp and random number. Signature:RES-{timestamp}-{random}
Purpose:
Creates a unique identifier for new reservations by combining the current timestamp (with special characters removed) and a random number between 0-99.
Example:
getReservationById()
Retrieves a reservation by its ID. Signature:The hotel object containing the reservations array
The unique reservation ID to search for
The reservation object if found, otherwise undefined
archiveReservation()
Moves a reservation from the active reservations list to the history. Signature:The hotel object to modify
The reservation to archive
createInvoice()
Creates an invoice object for a reservation. Signature:The hotel object
The reservation to create an invoice for
Invoice object with the following structure:
reservationId: The reservation IDguest: Guest informationroom: Object with room number and typecheckIn: Check-in datecheckOut: Check-out dateprice: Object with room price, extras price, and totalemisionDate: Invoice emission date
getCancellationCharge()
Calculates the cancellation penalty based on how close to check-in the cancellation occurs. Signature:The reservation to calculate cancellation charge for
The cancellation charge amount based on the cancellation policy:
- Less than 3 days before check-in: 100% of total price
- 3-7 days before check-in: 50% of total price
- 8 or more days before check-in: No charge (0)
- Returns undefined if reservation is undefined
The cancellation policy applies progressive penalties:
- 8+ days before: Free cancellation
- 3-7 days before: 50% charge
- Less than 3 days: Full charge
Room Management
getRoomByNumber()
Retrieves a room by its room number. Signature:The hotel object containing the rooms array
The room number to search for
The room object if found, otherwise undefined
getRoomsByStatus()
Filters rooms by their current status. Signature:Array of room objects to filter
The status to filter by (e.g., ‘available’, ‘occupied’, ‘maintenance’)
Array of rooms matching the specified status
getRoomsByType()
Filters rooms by their type. Signature:Array of room objects to filter
The room type to filter by (e.g., ‘single’, ‘double’, ‘suite’)
Array of rooms matching the specified type
isRoomAvailable()
Checks if a specific room is available for a given date range. Signature:The hotel object
The check-in date
The check-out date
The room number to check
True if the room is available for the date range, false if already reserved
getReservedRoomsByDate()
Retrieves all reserved room numbers for a specific date range. Signature:The hotel object
The check-in date
The check-out date
A Set of room numbers that are reserved for the date range
getReservedRoomByRoomNumber()
Retrieves the room object for a given reservation. Signature:The hotel object
The reservation containing the room number
The room object associated with the reservation
Pricing Functions
getNumberOfNights()
Calculates the number of nights between two dates. Signature:The check-in date (ISO string or PlainDate object)
The check-out date (ISO string or PlainDate object)
The number of nights between check-in and check-out
getTotalPrice()
Calculates the total room price for a date range. Signature:The room object containing pricePerNight
The check-in date
The check-out date
The total price (pricePerNight × numberOfNights)
getExtrasPrice()
Calculates the total price of extras. Signature:Array of extra objects, each containing
price and quantity propertiesThe sum of all extras (price × quantity for each extra)
updateTotalPriceWithExtras()
Calculates the final total price including extras. Signature:The reservation object containing the base totalPrice
Array of extra objects to add to the total
The updated total price (reservation.totalPrice + extras total)
History Management
getReservationsPlusHistory()
Combines active reservations and historical reservations. Signature:The hotel object containing reservations and history arrays
A deep clone of all reservations (active + history)
structuredClone to prevent mutations to the original arrays.
Example:
This function uses
structuredClone to create a deep copy, ensuring that modifications to the returned array don’t affect the original hotel data.