-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fetches the coach sequence of a connection
- Loading branch information
1 parent
5ba5e11
commit 5b9f323
Showing
3 changed files
with
177 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Controller, Get, Queries, Res, Route, Tags, type TsoaResponse } from "tsoa"; | ||
import { DateTime } from "luxon"; | ||
import { mapCoachSequence } from "../../lib/mapping.ts"; | ||
|
||
class SequenceQuery { | ||
lineDetails!: string; | ||
evaNumber!: string; | ||
date!: string; | ||
} | ||
|
||
@Route("journey/sequence") | ||
@Tags("Coach Sequences") | ||
export class SequenceController extends Controller { | ||
@Get() | ||
async getSequenceById( | ||
@Queries() query: SequenceQuery, | ||
@Res() badRequestResponse: TsoaResponse<400, { reason: string }> | ||
): Promise<any> { | ||
if (query.lineDetails === "") { | ||
return badRequestResponse(400, { reason: "lineDetails must not be empty" }); | ||
} | ||
if (!/^\d+$/.test(query.evaNumber)) { | ||
return badRequestResponse(400, { reason: "evaNumber is not an integer" }); | ||
} | ||
|
||
const dateValidation = DateTime.fromFormat(query.date, "yyyyMMdd"); | ||
if (!dateValidation.isValid) { | ||
return badRequestResponse(400, { reason: `${dateValidation.invalidExplanation}` }); | ||
} | ||
|
||
return fetchCoachSequence(query); | ||
} | ||
} | ||
|
||
const fetchCoachSequence = async (query: SequenceQuery): Promise<any> => { | ||
const request = await fetch(`https://app.vendo.noncd.db.de/mob/zuglaeufe/${query.lineDetails}/halte/by-abfahrt/${query.evaNumber}_${query.date}/wagenreihung`, { | ||
method: "GET", | ||
headers: { | ||
Accept: "application/x.db.vendo.mob.wagenreihung.v3+json", | ||
"Content-Type": "application/x.db.vendo.mob.wagenreihung.v3+json", | ||
"X-Correlation-ID": crypto.randomUUID() + "_" + crypto.randomUUID() | ||
} | ||
}); | ||
|
||
if (!request.ok) { | ||
throw new Error("Failed to fetch coach sequence"); | ||
} | ||
|
||
return mapCoachSequence(await request.json()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
export interface Sequence { | ||
track: Track; | ||
vehicleGroup?: VehicleGroup[]; | ||
direction?: "RIGHT" | "LEFT"; | ||
plannedTrack?: string; | ||
actualTrack?: string; | ||
} | ||
|
||
export interface Track { | ||
start: { position: number }; | ||
end: { position: number }; | ||
sections: Section[] | []; | ||
name: string; // name of the track | ||
} | ||
|
||
export interface Section { | ||
name: string; | ||
start: { position: number }; | ||
end: { position: number }; | ||
gleisabschnittswuerfelPosition: number; // ?????????????????????? | ||
firstClass: boolean; | ||
} | ||
|
||
export interface VehicleGroup { | ||
vehicles: Vehicle[]; | ||
tripReference: TripReference; | ||
designation: string; | ||
} | ||
|
||
export interface TripReference { | ||
type: string; | ||
line: string; | ||
destination: { name: string; }; | ||
category: string; | ||
fahrtNr: string; | ||
} | ||
|
||
export interface Vehicle { | ||
vehicleType: VehicleType; | ||
status: string; | ||
orientation: string; | ||
positionOnTrack: PositionOnTrack; | ||
equipment: Equipment[]; | ||
orderNumber?: number; // ?? | ||
} | ||
|
||
export interface VehicleType { | ||
category: string; | ||
model: string; | ||
firstClass: boolean; | ||
secondClass: boolean; | ||
} | ||
|
||
export interface PositionOnTrack { | ||
start: { position: number }; | ||
end: { position: number }; | ||
section: string; | ||
} | ||
|
||
/** | ||
* SEATS_SEVERELY_DISABLED | ||
* ZONE_FAMILY | ||
* ZONE_QUIET | ||
* INFO | ||
* CABIN_INFANT | ||
* AIR_CONDITION | ||
* TOILET_WHEELCHAIR | ||
* WHEELCHAIR_SPACE | ||
* SEATS_BAHN_COMFORT | ||
* BIKE_SPACE | ||
*/ | ||
export interface Equipment { | ||
type: string; | ||
status: string; | ||
} |