From f96c7a7e9da19a24b548dac5cdda7119b9e201c5 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Mon, 7 Aug 2023 12:03:09 +0100 Subject: [PATCH] Fix failure if NRCC messages are not present on StaffLDB Signed-off-by: Fred Boniface --- package-lock.json | 8 +++---- package.json | 2 +- src/services/ldb.services.js | 1 + src/utils/translators/ldb/staffStation.ts | 23 +++++++++++--------- test/utils/translators/ldb/stationOutputs.ts | 6 ++--- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index b790068..a3433f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "zlib": "^1.0.5" }, "devDependencies": { - "@owlboard/ts-types": "^0.0.7", + "@owlboard/ts-types": "^0.0.8", "@types/jest": "^29.5.3", "eslint": "^8.39.0", "jest": "^29.6.2", @@ -1855,9 +1855,9 @@ } }, "node_modules/@owlboard/ts-types": { - "version": "0.0.7", - "resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fts-types/-/0.0.7/ts-types-0.0.7.tgz", - "integrity": "sha512-VTxyQ+LsdFmKVJXkYj1wR7wNK03n3MRVVZ1lHW4Vl8oRVY0SvSYOpofFahMTSHAYNHcIwJgimEHewaQQEk0ruA==", + "version": "0.0.8", + "resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fts-types/-/0.0.8/ts-types-0.0.8.tgz", + "integrity": "sha512-MLAlioXFxqlKxHDZ2KdHQLx5/Kiebt5QtU59LFwGhn+gjtLJLfLdZCh7Kw1T3u+WOVN21fsJWdTRPhdvvFwnKw==", "dev": true, "license": "GPL-3.0-or-later" }, diff --git a/package.json b/package.json index 4cb7371..2d46ba4 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "zlib": "^1.0.5" }, "devDependencies": { - "@owlboard/ts-types": "^0.0.7", + "@owlboard/ts-types": "^0.0.8", "@types/jest": "^29.5.3", "eslint": "^8.39.0", "jest": "^29.6.2", diff --git a/src/services/ldb.services.js b/src/services/ldb.services.js index b4709ec..4d1ee33 100644 --- a/src/services/ldb.services.js +++ b/src/services/ldb.services.js @@ -67,6 +67,7 @@ async function arrDepBoardStaff(CRS) { const api = new ldb(ldbsvKey,true); console.time(`Fetch Staff LDB for ${CRS.toUpperCase()}`); const result = await api.call('GetArrivalDepartureBoardByCRS',options,false,false); + console.log(`Upstream API Size: ${resultSize}`) console.timeEnd(`Fetch Staff LDB for ${CRS.toUpperCase()}`) try { const _staffLdb = staffStationTransform(result) diff --git a/src/utils/translators/ldb/staffStation.ts b/src/utils/translators/ldb/staffStation.ts index 99d5ad8..f470768 100644 --- a/src/utils/translators/ldb/staffStation.ts +++ b/src/utils/translators/ldb/staffStation.ts @@ -22,6 +22,7 @@ export function transform(input: any): StaffLdb | null { console.timeEnd("StaffLdb Transformation") return output } catch (err) { + console.log("utils/translators/ldb/staffLdb.transform: Caught Error") console.log('Unable to parse data, assuming no data: ' + err) } console.timeEnd("StaffLdb Transformation") @@ -32,20 +33,23 @@ function transformDateTime(input: string): Date { return new Date(input) } -function transformNrcc(input: any): NrccMessage[] { +function transformNrcc(input: any): NrccMessage[] | undefined { let output: NrccMessage[] = [] let messages = input if (!Array.isArray(input?.message)) { messages = [input?.message] } - for (const item of messages) { - let message: NrccMessage = { - severity: item?.severity, - xhtmlMessage: removeNewlineAndPTag(item?.xhtmlMessage) + if (messages.length) { + for (const item of messages) { + let message: NrccMessage = { + severity: item?.severity, + xhtmlMessage: removeNewlineAndPTag(item?.xhtmlMessage) + } + output.push(message) } - output.push(message) - } - return output + return output + } + return undefined } function transformTrainServices(input: any): TrainServices[] { @@ -95,8 +99,7 @@ function transformLocation(input: any): ServiceLocation[] { } for (const item of locations) { const location: ServiceLocation = { - tiploc: item?.tiploc, - name: item?.locationName + tiploc: item?.tiploc } if (item?.via) { location.via = item.via diff --git a/test/utils/translators/ldb/stationOutputs.ts b/test/utils/translators/ldb/stationOutputs.ts index 68c552c..4f1c2dd 100644 --- a/test/utils/translators/ldb/stationOutputs.ts +++ b/test/utils/translators/ldb/stationOutputs.ts @@ -28,14 +28,12 @@ export const outputs: StaffLdb[] = [ length: 10, origin: [ { - tiploc: "PLYMTH", - name: "Plymouth" + tiploc: "PLYMTH" } ], destination: [ { - tiploc: "BHAMNWS", - name: "Birmingham New Street" + tiploc: "BHAMNWS" } ] }