Skip to content

Commit

Permalink
Fix bug with cancelled services
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminEHowe committed Jul 21, 2024
1 parent b5b9568 commit 395b177
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions functions/api/raildata/departures/v1/[[departures]].js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,19 @@ export async function onRequest(context) {
if ("trainServices" in nreDepartures) {
nreDepartures["trainServices"].forEach((nreService) => {
const service = {};

// cancellations
service["cancelled"] = nreService["isCancelled"];
if ("cancelReason" in nreService) {
if (nreService["cancelReason"].includes(CANCEL_REASON_PREFIX)) {
service["cancelReason"] = `Due to ${nreService["cancelReason"].substring(CANCEL_REASON_PREFIX.length)}`;
} else {
service["cancelReason"] = nreService["cancelReason"];
}
}

// verify that the service still calls at the filter station (if applicable)
if (crsFilter) {
if (crsFilter && !service["cancelled"]) {
const allCallingPoints = []
nreService["subsequentCallingPoints"].forEach((callingPoints => {
allCallingPoints.push(...callingPoints["callingPoint"]);
Expand All @@ -55,16 +65,6 @@ export async function onRequest(context) {
}
}

// cancellations
service["cancelled"] = nreService["isCancelled"];
if ("cancelReason" in nreService) {
if (nreService["cancelReason"].includes(CANCEL_REASON_PREFIX)) {
service["cancelReason"] = `Due to ${nreService["cancelReason"].substring(CANCEL_REASON_PREFIX.length)}`;
} else {
service["cancelReason"] = nreService["cancelReason"];
}
}

// timings
service["etd"] = nreService["etd"];
service["std"] = nreService["std"];
Expand Down

0 comments on commit 395b177

Please sign in to comment.