From 6ebb92af6cde40de44d561485399c56b2f979731 Mon Sep 17 00:00:00 2001 From: Maurice Date: Tue, 10 Nov 2026 09:28:43 +0100 Subject: [PATCH] fix(bookings): a hotel booking's card shows check-in and check-out when only the stay has them The edit form fell back to the linked stay's times, the cards read only the booking's metadata, so a hotel showed 15:00 and 11:00 when edited and no times in the list. The reservation list now carries the stay's check-in window and check-out, and the desktop facts and the phone card fall back to them. On the phone they come first, so a price or a seat cannot push them off the card. --- .../Planner/bookings/bookingFacts.test.ts | 22 ++++++++++++++++++- .../Planner/bookings/bookingFacts.ts | 9 ++++---- .../Planner/bookings/bookingsModel.ts | 21 ++++++++++++++++++ .../mobile/screens/trip/tabs/MBookingsTab.tsx | 15 ++++++++----- .../repositories/Reservations.repository.ts | 10 ++++++++- .../nest/plugins/protocol/output-contract.ts | 3 +++ .../Reservations.repository.test.ts | 3 ++- shared/src/reservation/reservation.schema.ts | 4 ++++ 8 files changed, 75 insertions(+), 12 deletions(-) diff --git a/client/src/components/Planner/bookings/bookingFacts.test.ts b/client/src/components/Planner/bookings/bookingFacts.test.ts index 7593e82a4..271cded38 100644 --- a/client/src/components/Planner/bookings/bookingFacts.test.ts +++ b/client/src/components/Planner/bookings/bookingFacts.test.ts @@ -1,4 +1,4 @@ -// FE-PLANNER-BKFACTS-001 to FE-PLANNER-BKFACTS-022 +// FE-PLANNER-BKFACTS-001 to FE-PLANNER-BKFACTS-024 import { describe, it, expect } from 'vitest'; import { buildDay, buildReservation } from '../../../../tests/helpers/factories'; import type { ReservationEndpoint } from '../../../types'; @@ -83,6 +83,26 @@ describe('bookingFacts: day', () => { }); }); +describe('bookingFacts: hotel times', () => { + it('FE-PLANNER-BKFACTS-023: a hotel without times of its own shows the stay's check-in and check-out', () => { + const f = bookingFacts(buildReservation({ + type: 'hotel', accommodation_start_day_id: 701, accommodation_end_day_id: 702, + accommodation_check_in: '15:00', accommodation_check_in_end: '18:00', accommodation_check_out: '11:00', + }), ctx()); + expect(cell(f, 'reservations.meta.checkIn')).toBe('15:00 → 18:00'); + expect(cell(f, 'reservations.meta.checkOut')).toBe('11:00'); + }); + + it('FE-PLANNER-BKFACTS-024: the booking's own times win over the stay's', () => { + const f = bookingFacts(buildReservation({ + type: 'hotel', metadata: JSON.stringify({ check_in_time: '14:00', check_out_time: '10:00' }), + accommodation_check_in: '15:00', accommodation_check_in_end: '18:00', accommodation_check_out: '11:00', + }), ctx()); + expect(cell(f, 'reservations.meta.checkIn')).toBe('14:00'); + expect(cell(f, 'reservations.meta.checkOut')).toBe('10:00'); + }); +}); + describe('bookingFacts: time', () => { it('FE-PLANNER-BKFACTS-008: start and end time with an arrow', () => { const f = bookingFacts(buildReservation({ reservation_time: '2025-06-01T09:05', reservation_end_time: '2025-06-01T11:30' }), ctx()); diff --git a/client/src/components/Planner/bookings/bookingFacts.ts b/client/src/components/Planner/bookings/bookingFacts.ts index 1e5cbea3d..b7698c715 100644 --- a/client/src/components/Planner/bookings/bookingFacts.ts +++ b/client/src/components/Planner/bookings/bookingFacts.ts @@ -2,7 +2,7 @@ import type { Day, Reservation, ReservationEndpoint } from '../../../types' import { formatPriceText, formatTime, splitReservationDateTime } from '../../../utils/formatters' import { getFlightLegs, getTrainLegs, usesStationRoute } from '../../../utils/flightLegs' import { safeExternalHref } from '../../../utils/safeUrl' -import { daySpan, parseMeta, type AssignmentLookupEntry } from './bookingsModel' +import { daySpan, hotelStayTimes, parseMeta, type AssignmentLookupEntry } from './bookingsModel' export interface FactsContext { t: (key: string, params?: Record) => string @@ -105,10 +105,11 @@ export function bookingFacts(r: Reservation, c: FactsContext): BookingFacts { if (!c.hasLinkedCost && meta.price != null && meta.price !== '') { cells.push({ label: t('reservations.price'), value: formatPriceText(meta.price, meta.priceCurrency, c.tripCurrency, locale) }) } - if (meta.check_in_time) { - cells.push({ label: t('reservations.meta.checkIn'), value: formatTime(meta.check_in_time, locale, timeFormat) + (meta.check_in_end_time ? ` → ${formatTime(meta.check_in_end_time, locale, timeFormat)}` : '') }) + const stay = hotelStayTimes(r, meta) + if (stay.checkIn) { + cells.push({ label: t('reservations.meta.checkIn'), value: formatTime(stay.checkIn, locale, timeFormat) + (stay.checkInEnd ? ` → ${formatTime(stay.checkInEnd, locale, timeFormat)}` : '') }) } - if (meta.check_out_time) cells.push({ label: t('reservations.meta.checkOut'), value: formatTime(meta.check_out_time, locale, timeFormat) }) + if (stay.checkOut) cells.push({ label: t('reservations.meta.checkOut'), value: formatTime(stay.checkOut, locale, timeFormat) }) // Per-segment codes (#1943), only on a real stopover booking. const legs = r.type === 'flight' ? getFlightLegs(r) : usesStationRoute(r.type) ? getTrainLegs(r) : [] diff --git a/client/src/components/Planner/bookings/bookingsModel.ts b/client/src/components/Planner/bookings/bookingsModel.ts index 17d8bf709..f0a75f595 100644 --- a/client/src/components/Planner/bookings/bookingsModel.ts +++ b/client/src/components/Planner/bookings/bookingsModel.ts @@ -103,6 +103,27 @@ export interface DaySpan { } /** The days a booking sits on. A hotel reads its stay from the accommodation, which is the source of truth for the range (#1383). */ +/** + * A hotel's check-in window and check-out: the booking's own metadata first, + * then the stay it is linked to. Times often live only on the stay, and the + * edit form already falls back the same way (reservationFormModel.ts). + */ +export function hotelStayTimes( + r: Reservation, + meta: { check_in_time?: string | null; check_in_end_time?: string | null; check_out_time?: string | null }, +): { checkIn: string | null; checkInEnd: string | null; checkOut: string | null } { + if (r.type !== 'hotel') { + return { checkIn: meta.check_in_time || null, checkInEnd: meta.check_in_end_time || null, checkOut: meta.check_out_time || null } + } + const checkIn = meta.check_in_time || r.accommodation_check_in || null + return { + checkIn, + // A window end belongs to the check-in it came with. + checkInEnd: meta.check_in_time ? meta.check_in_end_time || null : checkIn ? r.accommodation_check_in_end || null : null, + checkOut: meta.check_out_time || r.accommodation_check_out || null, + } +} + export function daySpan(r: Reservation, days: Day[]): DaySpan { const byId = (id?: number | null) => (id != null ? days.find(d => d.id === id) : undefined) if (r.type === 'hotel' && (r.accommodation_start_day_id || r.accommodation_end_day_id)) { diff --git a/client/src/mobile/screens/trip/tabs/MBookingsTab.tsx b/client/src/mobile/screens/trip/tabs/MBookingsTab.tsx index 05255b329..87229b78b 100644 --- a/client/src/mobile/screens/trip/tabs/MBookingsTab.tsx +++ b/client/src/mobile/screens/trip/tabs/MBookingsTab.tsx @@ -8,7 +8,7 @@ import { CardActions, CardDeleteSheet, CardFiles, CardNotes, CardTitleButton, Ca import { CardGrid, Field, ReservationPluginSlots, SectionHeader, StatusDot, TabScroller, TravelerAvatars, TravelerFilterRow } from './tabChrome' import { STATUS_COLOR, type MTabScreenProps } from './tabModel' import { cardWhen, parseTransportMeta, timeRange } from './transportsModel' -import { BOOKING_TYPE_COLOR } from '../../../../components/Planner/bookings/bookingsModel' +import { BOOKING_TYPE_COLOR, hotelStayTimes } from '../../../../components/Planner/bookings/bookingsModel' import { useReservationListFilter } from '../../../../components/Planner/bookings/useReservationListFilter' import { useReservationCard } from '../../../../components/Planner/bookings/useReservationCard' import { orderedEndpoints } from '../../../../utils/flightLegs' @@ -119,13 +119,18 @@ function BookingCard({ res, planner, canEdit, compact, onView }: { if (meta.price != null && meta.price !== '') { metaCells.push({ label: t('reservations.price'), value: formatPriceText(meta.price, meta.priceCurrency, planner.trip?.currency, locale) }) } - if (meta.check_in_time) { - metaCells.push({ + const stay = hotelStayTimes(res, meta) + // A hotel's times are its check-in and check-out; they come first, so a price + // or a seat cannot push them off the card. + const stayCells: { label: string; value: string }[] = [] + if (stay.checkIn) { + stayCells.push({ label: t('reservations.meta.checkIn'), - value: timeRange(meta.check_in_time, meta.check_in_end_time ?? null, locale, timeFormat), + value: timeRange(stay.checkIn, stay.checkInEnd, locale, timeFormat), }) } - if (meta.check_out_time) metaCells.push({ label: t('reservations.meta.checkOut'), value: formatTime(meta.check_out_time, locale, timeFormat) }) + if (stay.checkOut) stayCells.push({ label: t('reservations.meta.checkOut'), value: formatTime(stay.checkOut, locale, timeFormat) }) + metaCells.unshift(...stayCells) const files = filesFor(res, planner.files || []) diff --git a/server/src/db/repositories/Reservations.repository.ts b/server/src/db/repositories/Reservations.repository.ts index a61a5ce47..f64f6295c 100644 --- a/server/src/db/repositories/Reservations.repository.ts +++ b/server/src/db/repositories/Reservations.repository.ts @@ -31,7 +31,8 @@ export type { * RS18/RR1's shared joined projection — `SELECT r.*, d.day_number, p.name as * place_name, r.assignment_id, ap.place_id as accommodation_place_id, * acc_p.name as accommodation_name, ap.start_day_id as - * accommodation_start_day_id, ap.end_day_id as accommodation_end_day_id FROM + * accommodation_start_day_id, ap.end_day_id as accommodation_end_day_id, + * ap.check_in/check_in_end/check_out as accommodation_check_in/_check_in_end/_check_out FROM * reservations r LEFT JOIN days d ON r.day_id = d.id LEFT JOIN places p ON * r.place_id = p.id LEFT JOIN day_accommodations ap ON r.accommodation_id = * ap.id LEFT JOIN places acc_p ON ap.place_id = acc_p.id`. The service @@ -45,6 +46,10 @@ export interface ReservationJoinRow extends ReservationAllColumnsRow { accommodation_name: string | null; accommodation_start_day_id: number | null; accommodation_end_day_id: number | null; + /** The stay's own times, which a hotel booking's card falls back to. */ + accommodation_check_in: string | null; + accommodation_check_in_end: string | null; + accommodation_check_out: string | null; } /** @@ -394,6 +399,9 @@ export class ReservationsRepository extends TrekRepository { 'acc_p.name as accommodation_name', 'ap.start_day_id as accommodation_start_day_id', 'ap.end_day_id as accommodation_end_day_id', + 'ap.check_in as accommodation_check_in', + 'ap.check_in_end as accommodation_check_in_end', + 'ap.check_out as accommodation_check_out', ]); } diff --git a/server/src/nest/plugins/protocol/output-contract.ts b/server/src/nest/plugins/protocol/output-contract.ts index bff1a3856..8df3234d9 100644 --- a/server/src/nest/plugins/protocol/output-contract.ts +++ b/server/src/nest/plugins/protocol/output-contract.ts @@ -170,6 +170,9 @@ export const PLUGIN_ENTITY_CONTRACT = { 'accommodation_name', 'accommodation_start_day_id', 'accommodation_end_day_id', + 'accommodation_check_in', + 'accommodation_check_in_end', + 'accommodation_check_out', 'day_positions', 'endpoints', 'travelers', diff --git a/server/tests/unit/db/repositories/Reservations.repository.test.ts b/server/tests/unit/db/repositories/Reservations.repository.test.ts index eb126e297..088d4713b 100644 --- a/server/tests/unit/db/repositories/Reservations.repository.test.ts +++ b/server/tests/unit/db/repositories/Reservations.repository.test.ts @@ -525,7 +525,8 @@ describe('ReservationsRepository — AC37/AC40 (listIdMetadataByStay/listIdsBySt describe('ReservationsRepository — Task 2 reads (listForTrip / findWithJoins / findInTrip / listResyncCandidates / listForRestamp)', () => { const legacyJoinedSql = ` SELECT r.*, d.day_number as day_number, p.name as place_name, ap.place_id as accommodation_place_id, - acc_p.name as accommodation_name, ap.start_day_id as accommodation_start_day_id, ap.end_day_id as accommodation_end_day_id + acc_p.name as accommodation_name, ap.start_day_id as accommodation_start_day_id, ap.end_day_id as accommodation_end_day_id, + ap.check_in as accommodation_check_in, ap.check_in_end as accommodation_check_in_end, ap.check_out as accommodation_check_out FROM reservations r LEFT JOIN days d ON d.id = r.day_id LEFT JOIN places p ON p.id = r.place_id diff --git a/shared/src/reservation/reservation.schema.ts b/shared/src/reservation/reservation.schema.ts index fdfb4484b..3d9344d81 100644 --- a/shared/src/reservation/reservation.schema.ts +++ b/shared/src/reservation/reservation.schema.ts @@ -190,6 +190,10 @@ export const reservationSchema = z.object({ accommodation_name: z.string().nullable().optional(), accommodation_start_day_id: z.number().nullable().optional(), accommodation_end_day_id: z.number().nullable().optional(), + // The stay's check-in window and check-out, for a hotel booking whose own metadata has none. + accommodation_check_in: z.string().nullable().optional(), + accommodation_check_in_end: z.string().nullable().optional(), + accommodation_check_out: z.string().nullable().optional(), day_positions: z.record(z.string(), z.number()).nullable().optional(), endpoints: z.array(reservationEndpointSchema).optional(), // Trip members / named guests this booking is for (#1517). Joined in listReservations.