Skip to content

Commit

Permalink
chore: update coach sequence endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
AdriDevelopsThings committed Apr 30, 2024
1 parent ae7ff8a commit 8495927
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/fetcher/bahn_expert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ export const getEvaByStation = async (station: string): Promise<BahnExpertStatio
export const getIRISDepartures = async (evaNumber: number, lookahead?: number, lookbehind?: number): Promise<BahnExpertIrisAbfahrtenResponse | void> =>
await request(ApiModule.BAHN_EXPERT, '/iris/v2/abfahrten/[evaNumber]', { evaNumber: String(evaNumber), lookahead: lookahead ? String(lookahead) : null, lookbehind: lookbehind ? String(lookbehind) : null }, { ignoreStatusCodes: [404], cache: bahnExpertCache, cacheTTL: 60 * 10, useGetArguments: ['lookahead', 'lookbehind'] })

export const getCoachSequence = async (trainNumber: number, departure: string, evaNumber: number): Promise<BahnExpertCoachSequenceType | void> =>
await request(ApiModule.BAHN_EXPERT, '/reihung/v4/wagen/[trainNumber]', { trainNumber: String(trainNumber), departure, evaNumber: String(evaNumber) }, { ignoreStatusCodes: [404], cache: bahnExpertCache, cacheTTL: 60 * 5, useGetArguments: ['departure', 'evaNumber']})
export const getCoachSequence = async (trainNumber: number, trainCategory: string, initialDeparture: string, departure: string, evaNumber: number): Promise<BahnExpertCoachSequenceType | void> =>
await request(ApiModule.BAHN_EXPERT, '/coachSequence/v4/wagen/[trainNumber]', { trainNumber: String(trainNumber), category: trainCategory, initialDeparture, departure, evaNumber: String(evaNumber) }, { ignoreStatusCodes: [404], cache: bahnExpertCache, cacheTTL: 60 * 5, useGetArguments: ['initialDeparture', 'departure', 'evaNumber', 'category']})

export const getTrainDetails = async (trainName: string, station: number, date: string): Promise<BahnExpertDetailsType | void> =>
await request(ApiModule.BAHN_EXPERT, '/hafas/v2/details/[trainName]', { trainName, station: String(station), date }, { cache: bahnExpertCache, cacheTTL: 60 * 3, useGetArguments: [ 'station', 'date'], ignoreStatusCodes: [404]})
4 changes: 2 additions & 2 deletions src/rabbit/fetch_coach_sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getCoachSequence, getEvaByStation } from '../fetcher/bahn_expert.js'
import { debug } from '../logger.js'
import rabbitAsyncHandler from '../rabbitAsyncHandler.js'

type FetchCoachSequence = { trainId: number, trainNumber: number, trainType: string, evaDeparture: string, evaNumber: number }
type FetchCoachSequence = { trainId: number, trainNumber: number, trainType: string, evaDeparture: string, evaNumber: number, initialDeparture: string }


const getTrainVehicle = async (
Expand Down Expand Up @@ -96,7 +96,7 @@ const createTrainTripVehicle = async (trainId: number, groupIndex: number, train

export const fetch_coach_sequence = rabbitAsyncHandler(async (msg: FetchCoachSequence) => {
debug(`Starting to fetch coach sequence for ${msg.trainType}${msg.trainNumber} (ID ${msg.trainId})`)
const coachSequence = await getCoachSequence(msg.trainNumber, msg.evaDeparture, msg.evaNumber)
const coachSequence = await getCoachSequence(msg.trainNumber, msg.trainType, msg.initialDeparture, msg.evaDeparture, msg.evaNumber)
if (!coachSequence) return

const vehicleGroups = coachSequence.sequence.groups.filter(e => +e.number == msg.trainNumber)
Expand Down
1 change: 1 addition & 0 deletions src/rabbit/fetch_train_numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const fetch_train_numbers = rabbitAsyncHandler(async (msg: FetchTrainNumb
trainId,
trainNumber: +train.train.number,
trainType: train.train.type,
initialDeparture: train.initialDeparture,
evaDeparture: train.departure.scheduledTime,
evaNumber
})
Expand Down

0 comments on commit 8495927

Please sign in to comment.