From 19308e3969267a7e4fa91ee1b6040d7c4cd59643 Mon Sep 17 00:00:00 2001 From: Stephanos A Date: Mon, 6 Jul 2026 08:53:56 +0300 Subject: [PATCH] Package boarding station updates --- .../src/modules/packages/packages.service.ts | 21 ++++++++++++++++++- .../portal/src/app/packages/[id]/page.tsx | 10 ++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/apps/edr-passenger-api/src/modules/packages/packages.service.ts b/apps/edr-passenger-api/src/modules/packages/packages.service.ts index 3b14af6dd..294273d30 100644 --- a/apps/edr-passenger-api/src/modules/packages/packages.service.ts +++ b/apps/edr-passenger-api/src/modules/packages/packages.service.ts @@ -216,7 +216,26 @@ export class PackagesService { }, }); if (!pkg) throw new NotFoundException('Package not found'); - return { ...pkg, journeyType: pkg.returnScheduleId ? 'ROUND_TRIP' : 'ONE_WAY' }; + + // Fetch live route stops so the departure station dropdown always reflects + // the current route definition, not stale TripStopTime snapshots. + 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] })); + } + + return { + ...pkg, + journeyType: pkg.returnScheduleId ? 'ROUND_TRIP' : 'ONE_WAY', + outboundSchedule: { ...pkg.outboundSchedule, routeStops }, + }; } create(dto: CreatePackageDto) { diff --git a/apps/edr-passenger-web/portal/src/app/packages/[id]/page.tsx b/apps/edr-passenger-web/portal/src/app/packages/[id]/page.tsx index 16f9197e7..a38515e03 100644 --- a/apps/edr-passenger-web/portal/src/app/packages/[id]/page.tsx +++ b/apps/edr-passenger-web/portal/src/app/packages/[id]/page.tsx @@ -40,7 +40,7 @@ interface TrainInfo { operatorName: string; } -interface StopTime { +interface RouteStop { sequence: number; station: Station; } @@ -55,7 +55,7 @@ interface Schedule { originStation: Station; destinationStation: Station; train: TrainInfo; - stopTimes?: StopTime[]; + routeStops?: RouteStop[]; } interface PriceTier { @@ -438,9 +438,9 @@ export default function PackageDetailPage() { enabled: !!id, }); - // Build departure station list from the outbound schedule's route stops (ordered by sequence) - const routeStopStations: Station[] = pkg?.outboundSchedule?.stopTimes?.length - ? pkg.outboundSchedule.stopTimes.map((st) => st.station).filter(Boolean) + // Build departure station list from live route stops (always reflects current route definition) + const routeStopStations: Station[] = pkg?.outboundSchedule?.routeStops?.length + ? pkg.outboundSchedule.routeStops.map((rs) => rs.station).filter(Boolean) : []; const selectedTier = pkg?.priceTiers?.find((t) => t.id === selectedTierId);