Fix route datetime on lookup page

This commit is contained in:
Roba Boru
2026-07-14 21:22:04 +03:00
parent c2a7d99480
commit 660c611a1c

View File

@@ -1745,30 +1745,32 @@ export class BookingsService {
);
}
// Resolves the passenger's actual boarding/alighting stations for one leg from
// originStationId/destinationStationId (set when the booking covers only part of a
// longer multi-stop schedule, e.g. train runs A→D but the passenger booked B→D) via
// the schedule's stopTimes, falling back to the schedule's own full-route endpoints
// when there's no segment override (older records, or a booking that covers the
// whole run). Mirrors notifications.service.ts's resolveSegmentStations — that's
// already applied to SMS/email; this brings the booking API (voucher, detail page,
// confirmation) to the same behavior instead of always showing the train's full route.
// Resolves the passenger's actual boarding/alighting stations AND times for one leg
// from originStationId/destinationStationId (set when the booking covers only part of
// a longer multi-stop schedule, e.g. train runs A→D but the passenger booked B→D) via
// the schedule's stopTimes, falling back to the schedule's own full-route endpoints/
// times when there's no segment override (older records, or a booking that covers the
// whole run). Station resolution mirrors notifications.service.ts's
// resolveSegmentStations (already applied to SMS/email); the departureAt/arrivalAt
// resolution mirrors search.service.ts's leg construction (originStop.plannedDepartureAt
// / destStop.plannedArrivalAt) — this brings the booking API (voucher, detail page,
// confirmation) to the same behavior search results already have, instead of always
// showing the train's full-route span.
private resolveSegmentStations(
schedule: any,
originStationId: string | null | undefined,
destinationStationId: string | null | undefined,
): { origin: any; destination: any } {
): { origin: any; destination: any; departureAt: any; arrivalAt: any } {
const stopTimes: any[] = schedule?.stopTimes ?? [];
const findStation = (stationId: string | null | undefined, fallback: any) => {
if (stationId && stopTimes.length > 0) {
const stop = stopTimes.find((st: any) => st.stationId === stationId);
if (stop?.station) return stop.station;
}
return fallback ?? null;
};
const findStop = (stationId: string | null | undefined) =>
stationId && stopTimes.length > 0 ? stopTimes.find((st: any) => st.stationId === stationId) : undefined;
const originStop = findStop(originStationId);
const destStop = findStop(destinationStationId);
return {
origin: findStation(originStationId, schedule?.originStation),
destination: findStation(destinationStationId, schedule?.destinationStation),
origin: originStop?.station ?? schedule?.originStation ?? null,
destination: destStop?.station ?? schedule?.destinationStation ?? null,
departureAt: originStop?.plannedDepartureAt ?? schedule?.departureAt ?? null,
arrivalAt: destStop?.plannedArrivalAt ?? schedule?.arrivalAt ?? null,
};
}
@@ -1878,7 +1880,7 @@ export class BookingsService {
trainName: (booking as any).schedule.train.name,
origin: { id: outboundSegment.origin.id, name: outboundSegment.origin.name, code: outboundSegment.origin.code, city: outboundSegment.origin.city },
destination: { id: outboundSegment.destination.id, name: outboundSegment.destination.name, code: outboundSegment.destination.code, city: outboundSegment.destination.city },
departureAt: (booking as any).schedule.departureAt, arrivalAt: (booking as any).schedule.arrivalAt,
departureAt: outboundSegment.departureAt, arrivalAt: outboundSegment.arrivalAt,
},
returnSchedule: (booking as any).returnSchedule
? {
@@ -1887,7 +1889,7 @@ export class BookingsService {
trainName: (booking as any).returnSchedule.train.name,
origin: { id: returnSegment!.origin.id, name: returnSegment!.origin.name, code: returnSegment!.origin.code, city: returnSegment!.origin.city },
destination: { id: returnSegment!.destination.id, name: returnSegment!.destination.name, code: returnSegment!.destination.code, city: returnSegment!.destination.city },
departureAt: (booking as any).returnSchedule.departureAt, arrivalAt: (booking as any).returnSchedule.arrivalAt,
departureAt: returnSegment!.departureAt, arrivalAt: returnSegment!.arrivalAt,
}
: null,
passengers: (booking as any).seats?.map((bs: any) => ({