mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 04:08:11 +00:00
Fix price inconsistency
This commit is contained in:
@@ -236,18 +236,27 @@ export class PackagesService {
|
||||
});
|
||||
if (!pkg) throw new NotFoundException('Package not found');
|
||||
|
||||
// Fetch live route stops so the departure station dropdown always reflects
|
||||
// the current route definition, not stale TripStopTime snapshots.
|
||||
// Build departure station list from live route stops when a routeId exists,
|
||||
// falling back to the schedule's own stopTimes (already included in the query).
|
||||
let routeStops: { sequence: number; station: any }[] = [];
|
||||
if (pkg.outboundSchedule.routeId) {
|
||||
const stops = await this.prisma.routeStop.findMany({
|
||||
where: { routeId: pkg.outboundSchedule.routeId },
|
||||
orderBy: { sequence: 'asc' },
|
||||
});
|
||||
const stationIds = stops.map((s) => s.stationId);
|
||||
const stations = await this.prisma.station.findMany({ where: { id: { in: stationIds } } });
|
||||
const stationMap = Object.fromEntries(stations.map((s) => [s.id, s]));
|
||||
routeStops = stops.map((s) => ({ sequence: s.sequence, station: stationMap[s.stationId] }));
|
||||
if (stops.length > 0) {
|
||||
const stationIds = stops.map((s) => s.stationId);
|
||||
const stations = await this.prisma.station.findMany({ where: { id: { in: stationIds } } });
|
||||
const stationMap = Object.fromEntries(stations.map((s) => [s.id, s]));
|
||||
routeStops = stops.map((s) => ({ sequence: s.sequence, station: stationMap[s.stationId] }));
|
||||
}
|
||||
}
|
||||
// Fall back to the schedule's own TripStopTimes when RouteStop table has no rows
|
||||
// for this route (e.g. route exists but stops were never seeded).
|
||||
if (routeStops.length === 0) {
|
||||
routeStops = (pkg.outboundSchedule.stopTimes ?? [])
|
||||
.filter((st: any) => st.station)
|
||||
.map((st: any) => ({ sequence: st.sequence, station: st.station }));
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user