Fix: a booking arriving in a few days showed 'booked' instead of 'vacant'
resolveGoverningBooking() was letting an upcoming (not-today) booking govern colour, so any room with something booked within the 7-day lookahead showed green 'Booked' regardless of how far off the arrival was. 'booked' should only apply when someone's actually arriving tonight. Now a booking only governs state/colour when it covers today (arriving today, mid-stay, or departing today) — otherwise the room is genuinely vacant. The soonest upcoming booking (if any) is surfaced separately as vacant_nights, a countdown to the next arrival, purely informational and no longer tied to colour. Dashboard shows 'Vacant N nights' when something's booked within the window, or 'Vacant 7+ nights' when nothing was found in the fetched window at all. New zone_state.vacant_nights column, threaded through saveZoneState/pollOnce/status.js. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
915fc0039c
commit
dc8c9df719
5 changed files with 60 additions and 31 deletions
|
|
@ -108,6 +108,10 @@ export async function initDb() {
|
|||
current_night INT,
|
||||
total_nights INT,
|
||||
has_next_booking BOOLEAN NOT NULL DEFAULT FALSE, -- turnover hint: another booking follows a departure today
|
||||
-- Only set when room_state = 'vacant': nights until the next known arrival
|
||||
-- within the scheduler's fetch window, or NULL if nothing was found in that
|
||||
-- window at all (displayed as an open-ended "7+ nights" rather than a count).
|
||||
vacant_nights INT,
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
|
|
@ -195,6 +199,7 @@ export async function initDb() {
|
|||
await pool.query(`ALTER TABLE zone_state ADD COLUMN IF NOT EXISTS current_night INT`)
|
||||
await pool.query(`ALTER TABLE zone_state ADD COLUMN IF NOT EXISTS total_nights INT`)
|
||||
await pool.query(`ALTER TABLE zone_state ADD COLUMN IF NOT EXISTS has_next_booking BOOLEAN NOT NULL DEFAULT FALSE`)
|
||||
await pool.query(`ALTER TABLE zone_state ADD COLUMN IF NOT EXISTS vacant_nights INT`)
|
||||
|
||||
await seedDefaults()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue