fix(wallet): date a booking's pass by its stay or linked day when it has no time of its own

The Wallet pass took its date only from the booking's own time or, for a
journey, its departure stop. A hotel whose check-in and check-out live on its
stay, and a booking linked to a day that carries only a clock, have neither,
so Wallet answered "Give the booking a date first" for a booking the app
shows with its dates. A TestFlight tester hit it with a hotel booked from
8 to 11 January.

The pass context now reads the dates of the days a booking is linked to and,
for a hotel, the first and last day of its stay with its check-in and
check-out times. The pass falls back to them in the order the app uses
(bookingDates): the booking's own time first, then the stay or the linked
day, with the booking's or the stay's clock. A booking with no date anywhere
is still refused.
This commit is contained in:
Maurice
2026-11-25 10:25:10 +01:00
parent c1c77d89b5
commit b6c50eb146
6 changed files with 237 additions and 7 deletions
@@ -3,7 +3,7 @@ import { accommodationIdMatches } from './reservation-accommodation';
import type { SqlEntityManager } from '@mikro-orm/sql';
/** The tables `passContextQuery` reads. */
type PassContextDB = Pick<DB, 'reservations' | 'trips' | 'places' | 'day_accommodations'>;
type PassContextDB = Pick<DB, 'reservations' | 'trips' | 'places' | 'day_accommodations' | 'days'>;
/** What a booking's Wallet pass needs beyond the booking: where it is, and the trip's name. */
export interface ReservationPassContext {
@@ -11,11 +11,21 @@ export interface ReservationPassContext {
place_lat: number | null;
place_lng: number | null;
place_name: string | null;
/** The date of the day the booking is linked to, and of the day it ends on. */
day_date: string | null;
end_day_date: string | null;
/** A hotel's stay: its first and last day, and its check-in and check-out times. */
stay_start_date: string | null;
stay_end_date: string | null;
stay_check_in: string | null;
stay_check_out: string | null;
}
/**
* The trip's title and the place a booking is at (its own place, else its
* stay's), for its Apple Wallet pass (`ReservationsRepository.findPassContext`).
* stay's), for its Apple Wallet pass (`ReservationsRepository.findPassContext`),
* and the dates of the days it is linked to: a day-linked booking, or a hotel
* whose dates live on its stay, carries no date of its own.
* Scoped to the trip, so a booking of another trip reads as none. Kept out of
* the repository file, which is at its size baseline. `em` is the repository's
* own, which has checked the request context.
@@ -35,6 +45,10 @@ export async function passContextQuery(
join.on((eb) => accommodationIdMatches(platform, eb, 'r.accommodation_id', 'ap.id')),
)
.leftJoin('places as acc_p', 'acc_p.id', 'ap.place_id')
.leftJoin('days as rd', 'rd.id', 'r.day_id')
.leftJoin('days as red', 'red.id', 'r.end_day_id')
.leftJoin('days as asd', 'asd.id', 'ap.start_day_id')
.leftJoin('days as aed', 'aed.id', 'ap.end_day_id')
.where('r.id', '=', id)
.where('r.trip_id', '=', trip_id)
.select([
@@ -42,6 +56,12 @@ export async function passContextQuery(
(eb) => eb.fn.coalesce('p.lat', 'acc_p.lat').as('place_lat'),
(eb) => eb.fn.coalesce('p.lng', 'acc_p.lng').as('place_lng'),
(eb) => eb.fn.coalesce('p.name', 'acc_p.name').as('place_name'),
'rd.date as day_date',
'red.date as end_day_date',
'asd.date as stay_start_date',
'aed.date as stay_end_date',
'ap.check_in as stay_check_in',
'ap.check_out as stay_check_out',
])
.executeTakeFirst();
return row as ReservationPassContext | undefined;