mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 02:34:21 +00:00
fix(airtrail): read and write the passenger list under both its names
AirTrail 3.12.0 renamed the flight's passenger list from `seats` to `passengers` and moved flightReason from the flight onto each passenger. There is no alias in either direction: a 3.12.0 instance returns `passengers` and `null` for `seats`, and its save schema accepts only `passengers`. TREK read `raw.seats` everywhere, so against a 3.12.0 instance it found nothing. The seat never made it into the import, and because a pull rebuilds the metadata from the AirTrail payload, flights that had already been imported lost the seat they had. That is the report. Flights whose sync is switched off were never re-pulled, which is why theirs survived. Two more breaks came from the same rename and were not reported. The flight reason stopped importing for the same reason. And the writeback pushed the seat under `seats`, which the new schema strips, so a seat edited in TREK was quietly dropped on the way out; it did not fail loudly because the spread of the fetched flight carried AirTrail's own `passengers` through untouched. Both shapes are handled rather than switched between, because instances on 3.11 and older are still out there: reads take `passengers ?? seats`, and the save body carries the manifest under both keys. Neither schema is strict, so each version keeps the key it knows and strips the other. The snapshot hash deliberately keeps feeding the manifest in under the same key. An unchanged flight on an older instance therefore hashes exactly as before and does not re-sync, while a 3.12.0 flight hashes differently once and pulls the missing seat back in. There is a pinned-hash test guarding the first half. Verified against real instances rather than the docs: a 3.11.1 and a 3.12.0 container, seat imported from each, a seat edited in TREK written back and read out of AirTrail again, and the pre-fix build failing the same checks on 3.12.0. Closes #1931
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { localParts } from '../common/timezoneService';
|
||||
import { flightPassengers, ownPassenger } from './airtrail.client';
|
||||
import type { AirtrailAirport, AirtrailFlightRaw, AirtrailNamedCode } from './airtrail.client';
|
||||
import type { AirtrailFlight } from '@trek/shared';
|
||||
|
||||
@@ -40,7 +41,7 @@ export function normalizeFlight(raw: AirtrailFlightRaw): AirtrailFlight {
|
||||
airline: entityName(raw.airline),
|
||||
flightNumber: raw.flightNumber ?? null,
|
||||
aircraft: entityCode(raw.aircraft),
|
||||
seatClass: (raw.seats?.find((s) => s.userId) ?? raw.seats?.[0])?.seatClass ?? null,
|
||||
seatClass: ownPassenger(raw)?.seatClass ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -124,7 +125,7 @@ export function mapFlightToReservation(raw: AirtrailFlightRaw): MappedReservatio
|
||||
needsReview = 1;
|
||||
}
|
||||
|
||||
const seat = raw.seats?.find((s) => s.userId) ?? raw.seats?.[0];
|
||||
const seat = ownPassenger(raw);
|
||||
const airlineName = entityName(raw.airline);
|
||||
const airlineCode = entityCode(raw.airline);
|
||||
const aircraftCode = entityCode(raw.aircraft);
|
||||
@@ -136,7 +137,9 @@ export function mapFlightToReservation(raw: AirtrailFlightRaw): MappedReservatio
|
||||
if (raw.flightNumber) metadata.flight_number = raw.flightNumber;
|
||||
if (aircraftCode) metadata.aircraft = aircraftCode;
|
||||
if (raw.aircraftReg) metadata.aircraft_reg = raw.aircraftReg;
|
||||
if (raw.flightReason) metadata.flight_reason = raw.flightReason;
|
||||
// 3.12.0 moved the reason onto the passenger; older instances keep it on the flight.
|
||||
const flightReason = raw.flightReason ?? seat?.flightReason ?? null;
|
||||
if (flightReason) metadata.flight_reason = flightReason;
|
||||
if (seat?.seatNumber) metadata.seat = seat.seatNumber;
|
||||
|
||||
// The flight number already carries the airline prefix (e.g. "SAS983"), so it
|
||||
@@ -227,7 +230,7 @@ export function mapFlightsToMultiLegReservation(
|
||||
needsReview = 1;
|
||||
}
|
||||
|
||||
const seat = f.seats?.find((s) => s.userId) ?? f.seats?.[0];
|
||||
const seat = ownPassenger(f);
|
||||
const airline = entityName(f.airline);
|
||||
legs.push({
|
||||
from: airportCode(f.from),
|
||||
@@ -304,9 +307,9 @@ export function canonicalHash(raw: AirtrailFlightRaw): string {
|
||||
flightNumber: raw.flightNumber ?? null,
|
||||
aircraft: entityCode(raw.aircraft),
|
||||
aircraftReg: raw.aircraftReg ?? null,
|
||||
flightReason: raw.flightReason ?? null,
|
||||
flightReason: raw.flightReason ?? ownPassenger(raw)?.flightReason ?? null,
|
||||
note: raw.note ?? null,
|
||||
seats: (raw.seats ?? [])
|
||||
seats: flightPassengers(raw)
|
||||
.map((s) => ({
|
||||
userId: s.userId ?? null,
|
||||
guestName: s.guestName ?? null,
|
||||
|
||||
Reference in New Issue
Block a user