Fix failure if NRCC messages are not present on StaffLDB

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-08-07 12:03:09 +01:00
parent ae1a467c97
commit f96c7a7e9d
5 changed files with 21 additions and 19 deletions

8
package-lock.json generated
View File

@ -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"
},

View File

@ -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",

View File

@ -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)

View File

@ -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,12 +33,13 @@ 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]
}
if (messages.length) {
for (const item of messages) {
let message: NrccMessage = {
severity: item?.severity,
@ -46,6 +48,8 @@ function transformNrcc(input: any): NrccMessage[] {
output.push(message)
}
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

View File

@ -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"
}
]
}