Fix price inconsistency

This commit is contained in:
Roba Boru
2026-07-19 22:46:36 +03:00
parent 996c0d8896
commit d43229528e
6 changed files with 153 additions and 108 deletions

View File

@@ -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 {