Skip to content

Commit 397ab94

Browse files
Fix updated Träwelling API
Too many changes to summarise, basically fix API breakage until I can successfully check in
1 parent 59a13a3 commit 397ab94

29 files changed

Lines changed: 557 additions & 350 deletions

File tree

src/app/api/dashboard/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function GET(request: Request) {
3636

3737
transformedData.forEach((status) => {
3838
status.journey.line.appearance = getAppearanceForLine(
39-
identifyLineByMagic(status.journey.hafasTripId, status.journey.line)
39+
status.journey.line,
4040
);
4141
});
4242

src/app/api/stations/[station]/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { identifyLineByMagic } from '@/helpers/identifyLineByMagic';
22
import { createLineAppearanceDataset } from '@/helpers/lineAppearance';
33
import { authOptions } from '@/pages/api/auth/[...nextauth]';
44
import { TraewellingSdk } from '@/traewelling-sdk';
5-
import { transformHAFASTrip } from '@/traewelling-sdk/transformers';
5+
import { transformTrwlDeparture } from '@/traewelling-sdk/transformers';
66
import { TransportType } from '@/traewelling-sdk/types';
77
import { AboardStation, AboardTrip } from '@/types/aboard';
88
import createErrorResponse from '@/utils/api/createErrorResponse';
@@ -84,12 +84,12 @@ export async function GET(
8484
} as AboardStation,
8585
times: data.meta?.times,
8686
},
87-
trips: data.trips.map(transformHAFASTrip),
87+
trips: data.trips.map(transformTrwlDeparture),
8888
};
8989

9090
transformedData.trips.forEach((trip) => {
9191
trip.line.appearance = getAppearanceForLine(
92-
identifyLineByMagic(trip.hafasId, trip.line)
92+
trip.line,
9393
);
9494
});
9595

src/app/api/trips/route.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { getServerSession } from 'next-auth';
77

88
export async function GET(request: Request) {
99
try {
10-
const { hafasTripId, lineName, start } = getSafeURLParams({
10+
const { hafasTripId, lineName } = getSafeURLParams({
1111
url: request.url,
12-
requiredParams: ['hafasTripId', 'lineName', 'start'],
12+
requiredParams: ['hafasTripId', 'lineName'],
1313
});
1414

1515
const session = await getServerSession(authOptions);
@@ -23,7 +23,6 @@ export async function GET(request: Request) {
2323
const data = await TraewellingSdk.trains.trip({
2424
hafasTripId,
2525
lineName,
26-
start,
2726
});
2827

2928
return createResponse({

src/app/status/[id]/page.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ async function getStatusData(id: string) {
3131
async function getTripData(
3232
hafasTripId: string,
3333
lineName: string,
34-
start: string
3534
) {
3635
try {
3736
const trip = await TraewellingSdk.trains.trip({
3837
hafasTripId,
3938
lineName,
40-
start,
4139
});
4240

4341
if (!('id' in trip)) {
@@ -70,7 +68,6 @@ export default async function Page({ params }: StatusPageProps) {
7068
const tripData = await getTripData(
7169
status.journey.hafasTripId,
7270
status.journey.line.name,
73-
status.journey.origin.station.trwlId!.toString()
7471
);
7572

7673
if ('trwlId' in tripData) {

src/app/traewelling/trips/route.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { getServerSession } from 'next-auth';
77

88
export async function GET(request: Request) {
99
try {
10-
const { hafasTripId, lineName, start } = getSafeURLParams({
10+
const { hafasTripId, lineName } = getSafeURLParams({
1111
url: request.url,
12-
requiredParams: ['hafasTripId', 'lineName', 'start'],
12+
requiredParams: ['hafasTripId', 'lineName'],
1313
});
1414

1515
const session = await getServerSession(authOptions);
@@ -23,7 +23,6 @@ export async function GET(request: Request) {
2323
const data = await TraewellingSdk.trains.trip({
2424
hafasTripId,
2525
lineName,
26-
start,
2726
});
2827

2928
return createResponse({

src/components/CheckIn/CheckIn.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { useCurrentStatus } from '@/hooks/useCurrentStatus/useCurrentStatus';
44
import useUmami from '@/hooks/useUmami/useUmami';
55
import { CheckinInput } from '@/traewelling-sdk/functions/trains';
6-
import { Station, Stop } from '@/traewelling-sdk/types';
6+
import { Station, Stopover } from '@/traewelling-sdk/types';
77
import { AboardTrip } from '@/types/aboard';
88
import { Session } from 'next-auth';
99
import { useSession } from 'next-auth/react';
@@ -49,12 +49,12 @@ const post = async (status: CheckinInput, session?: Session | null) => {
4949
const CheckIn = () => {
5050
const { data: session } = useSession();
5151
const [departureTime, setDepartureTime] = useState<string>();
52-
const [destination, setDestination] = useState<Stop>();
52+
const [destination, setDestination] = useState<Stopover>();
5353
const [error, setError] = useState<string>();
5454
const [isOpen, setIsOpen] = useState(false);
5555
const [message, setMessage] = useState('');
5656
const [origin, setOrigin] =
57-
useState<Pick<Station, 'id' | 'ibnr' | 'name' | 'rilIdentifier'>>();
57+
useState<Station>();
5858
const [query, setQuery] = useState('');
5959
const [step, setStep] = useState<CheckInStep>('origin');
6060
const [travelType, setTravelType] = useState(0);
@@ -73,10 +73,9 @@ const CheckIn = () => {
7373
body: message,
7474
business: travelType,
7575
departure: trip?.departure?.planned!,
76-
destination: destination!.evaIdentifier,
77-
ibnr: true,
76+
destination: destination!.id,
7877
lineName: trip!.line.name,
79-
start: trip?.departureStation?.ibnr!,
78+
start: trip?.departureStation?.trwlId ?? -1,
8079
tripId: trip!.hafasId!,
8180
visibility: visibility,
8281
},

src/components/CheckIn/DestinationStep/DestinationStep.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const DestinationStep = () => {
2525
trip?.hafasId ?? '',
2626
trip?.line.name ?? '',
2727
trip?.departure?.planned ?? '',
28-
trip?.departureStation?.evaId?.toString() ?? ''
28+
trip?.departureStation?.trwlId ?? -1,
2929
);
3030

3131
const schedule = parseSchedule({
@@ -101,11 +101,11 @@ const DestinationStep = () => {
101101
{stops.map((stop, index) => (
102102
<li key={index}>
103103
<Stop
104-
arrivalAt={stop.arrival ?? stop.departure}
104+
arrivalAt={stop.arrivalReal ?? stop.arrivalPlanned ?? stop.departureReal ?? stop.departurePlanned}
105105
isCancelled={stop.cancelled}
106106
isDelayed={
107107
stop.isArrivalDelayed ||
108-
(!stop.arrival && stop.isDepartureDelayed)
108+
(!stop.arrivalReal && stop.isDepartureDelayed)
109109
}
110110
name={stop.name}
111111
onClick={() => setDestination(stop)}

src/components/CheckIn/FinalStep/FinalStep.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
MdOutlineGroups,
1818
MdOutlineLockOpen,
1919
MdOutlineLockPerson,
20+
MdShield,
2021
MdSwapCalls,
2122
MdWorkOutline,
2223
} from 'react-icons/md';
@@ -61,6 +62,10 @@ const VISIBILITIES = [
6162
icon: <MdFingerprint size={18} />,
6263
name: 'Nur angemeldete Personen',
6364
},
65+
{
66+
icon: <MdShield size={18} />,
67+
name: 'Nur vertrauten Personen',
68+
},
6469
];
6570

6671
const FinalStep = () => {
@@ -80,7 +85,7 @@ const FinalStep = () => {
8085
} = useContext(CheckInContext);
8186

8287
const arrivalSchedule = parseSchedule({
83-
actual: destination?.arrival,
88+
actual: destination?.arrivalReal,
8489
planned: destination?.arrivalPlanned!,
8590
});
8691

src/components/CheckIn/OriginStep/OriginStep.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ const OriginStep = () => {
3232
{stations && stations.length > 0 && (
3333
<ul className={styles.stationList}>
3434
{stations.map((station) => (
35-
<li key={station.ibnr}>
35+
<li key={station.id}>
3636
<Station
3737
name={station.name}
3838
onClick={() => setOrigin(station)}
3939
query={query}
40-
rilIdentifier={station.rilIdentifier}
40+
rilIdentifier={station.identifiers.filter(id => id.type === 'de_db_ril100')[0]?.identifier}
4141
/>
4242
</li>
4343
))}
@@ -71,11 +71,11 @@ const OriginStep = () => {
7171
{recentStations && recentStations.length > 0 && (
7272
<ul className={styles.stationList}>
7373
{recentStations.map((station) => (
74-
<li key={station.ibnr}>
74+
<li key={station.id}>
7575
<Station
7676
name={station.name}
7777
onClick={() => setOrigin(station)}
78-
rilIdentifier={station.rilIdentifier}
78+
rilIdentifier={station.identifiers.filter(id => id.type === 'de_db_ril100')[0]?.identifier}
7979
/>
8080
</li>
8181
))}

src/components/CheckIn/Search/Search.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,7 @@ const Search = () => {
6060
simpleEvent('nearby_clicked');
6161

6262
const station = (await response.json()) as NearbyResponse;
63-
setOrigin({
64-
id: station.id,
65-
ibnr: station.ibnr,
66-
name: station.name,
67-
rilIdentifier: station.rilIdentifier,
68-
});
63+
setOrigin(station);
6964
});
7065
};
7166

0 commit comments

Comments
 (0)