mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 21:11:14 +00:00
fix(planner): show each leg's own seat on a flight with a stop
A flight with a stop saves a seat per leg, but every view read the booking's flat seat, which mirrors the first leg's. A seat booked only on the second leg showed nowhere, and one on the first leg showed on both. #2701 had fixed this for trains only. - getFlightLegs reads each leg's seat. The first leg falls back to the flat seat, as the booking form does, so older bookings keep theirs. - bookingSeats lists the seat of every leg that has one with its route. The detail views (the phone's transport sheet, the booking detail) show each leg's seat under its route ("Seat IST → JFK"), and a leg opened from its row shows its own. The cards and field grids (bookings list, the phone's Bookings and Transports tabs, the day plan's transport detail) hold every seat in one Seat cell, so a card cutting its grid short no longer drops the second leg's. - The day plan's flight leg rows carry their seat, and the PDF prints a flight's seat, direct or per leg. - The watch and the Wallet pass name every leg's seat of the booking. - A legs-only MCP update sets the flat seat, airline and flight number (train number and platform) again from the new first leg, so a seat taken off the first leg does not live on in the flat seat. A flat value the stored first leg never had stays. Closes #3158
This commit is contained in:
@@ -146,6 +146,23 @@ const legsSchema = z.array(z.strictObject(transportLegInputSchema.shape)).option
|
||||
|
||||
type MetaRecord = Record<string, unknown>;
|
||||
|
||||
/**
|
||||
* The stored metadata a legs-only update starts from, without the flat keys
|
||||
* that only mirrored the stored first leg's own detail. Those are set again
|
||||
* from the new legs; kept, a first leg's seat taken away stayed in the flat
|
||||
* seat, and the planner, which reads that as the first leg's, brought it back.
|
||||
* A flat value the first leg never had (an older booking) is the booking's own
|
||||
* and stays.
|
||||
*/
|
||||
function withoutLegMirrors(stored: MetaRecord, type: string): MetaRecord {
|
||||
const mirrored = type === 'flight' ? ['airline', 'flight_number', 'seat'] : ['train_number', 'platform', 'seat'];
|
||||
const leg: unknown = Array.isArray(stored.legs) ? stored.legs[0] : null;
|
||||
const firstLeg = leg && typeof leg === 'object' ? (leg as MetaRecord) : null;
|
||||
return Object.fromEntries(
|
||||
Object.entries(stored).filter(([key, value]) => !(firstLeg && mirrored.includes(key) && firstLeg[key] === value)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* `reservations.metadata` as stored: a JSON string, or (from an old
|
||||
* double-encoding bug the client readers still heal around) a JSON string of a
|
||||
@@ -827,8 +844,8 @@ export class ReservationsMcp {
|
||||
})),
|
||||
// metadata keeps replacing wholesale when it is sent; a legs-only update
|
||||
// must not drop departure_airport / airtrail_ids / transit, so it merges
|
||||
// into what is stored instead.
|
||||
baseMetadata: metadata !== undefined ? { ...metadata } : { ...stored },
|
||||
// into what is stored instead, less the first leg's mirrored detail.
|
||||
baseMetadata: metadata !== undefined ? { ...metadata } : withoutLegMirrors(stored, resolvedType),
|
||||
previousLegs: Array.isArray(stored.legs) ? stored.legs as unknown[] : [],
|
||||
startDayId: start_day_id,
|
||||
endDayId: end_day_id,
|
||||
|
||||
@@ -193,6 +193,23 @@ function text(meta: Record<string, unknown>, key: string, max = 64): string | un
|
||||
return typeof value === 'string' || typeof value === 'number' ? clean(value, max) : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* The seat a pass shows. One pass covers a whole flight or train with a stop,
|
||||
* so it lists the seat of every leg that has one (the first leg falling back
|
||||
* to the flat seat, which mirrors it); before, a seat booked only on a later
|
||||
* leg was missing and the first leg's stood for the whole route.
|
||||
*/
|
||||
function seatsOf(meta: Record<string, unknown>): string | undefined {
|
||||
const legs = Array.isArray(meta.legs) && meta.legs.length > 1 ? (meta.legs as unknown[]) : null;
|
||||
if (!legs) return text(meta, 'seat', 16);
|
||||
const seats = legs.flatMap((leg, i) => {
|
||||
const own = leg && typeof leg === 'object' ? (leg as Record<string, unknown>).seat : undefined;
|
||||
const seat = typeof own === 'string' && own.trim() ? own : i === 0 ? meta.seat : undefined;
|
||||
return typeof seat === 'string' && seat.trim() ? [seat.trim()] : [];
|
||||
});
|
||||
return seats.length ? clean(seats.join(' / '), 16) : undefined;
|
||||
}
|
||||
|
||||
/** A stable serial for the booking, so adding its pass again replaces the one in Wallet. */
|
||||
export function serialFor(reservation: WalletPassSource['reservation']): string {
|
||||
const digest = createHash('sha256')
|
||||
@@ -258,7 +275,7 @@ export function buildWalletPassRequest(src: WalletPassSource, words: WalletWords
|
||||
add(words.flightNumber, number || undefined);
|
||||
}
|
||||
if (kind === 'train') add(words.trainNumber, text(meta, 'train_number', 20));
|
||||
add(words.seat, text(meta, 'seat', 16));
|
||||
add(words.seat, seatsOf(meta));
|
||||
add(words.platform, text(meta, 'platform', 16));
|
||||
if (endLocal) add(words.arrival, when(endLocal.date, endLocal.time));
|
||||
} else if (kind === 'hotel') {
|
||||
|
||||
Reference in New Issue
Block a user