Fix failure if NRCC messages are not present on StaffLDB
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
ae1a467c97
commit
f96c7a7e9d
8
package-lock.json
generated
8
package-lock.json
generated
@ -24,7 +24,7 @@
|
|||||||
"zlib": "^1.0.5"
|
"zlib": "^1.0.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@owlboard/ts-types": "^0.0.7",
|
"@owlboard/ts-types": "^0.0.8",
|
||||||
"@types/jest": "^29.5.3",
|
"@types/jest": "^29.5.3",
|
||||||
"eslint": "^8.39.0",
|
"eslint": "^8.39.0",
|
||||||
"jest": "^29.6.2",
|
"jest": "^29.6.2",
|
||||||
@ -1855,9 +1855,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@owlboard/ts-types": {
|
"node_modules/@owlboard/ts-types": {
|
||||||
"version": "0.0.7",
|
"version": "0.0.8",
|
||||||
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fts-types/-/0.0.7/ts-types-0.0.7.tgz",
|
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fts-types/-/0.0.8/ts-types-0.0.8.tgz",
|
||||||
"integrity": "sha512-VTxyQ+LsdFmKVJXkYj1wR7wNK03n3MRVVZ1lHW4Vl8oRVY0SvSYOpofFahMTSHAYNHcIwJgimEHewaQQEk0ruA==",
|
"integrity": "sha512-MLAlioXFxqlKxHDZ2KdHQLx5/Kiebt5QtU59LFwGhn+gjtLJLfLdZCh7Kw1T3u+WOVN21fsJWdTRPhdvvFwnKw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "GPL-3.0-or-later"
|
"license": "GPL-3.0-or-later"
|
||||||
},
|
},
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
"zlib": "^1.0.5"
|
"zlib": "^1.0.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@owlboard/ts-types": "^0.0.7",
|
"@owlboard/ts-types": "^0.0.8",
|
||||||
"@types/jest": "^29.5.3",
|
"@types/jest": "^29.5.3",
|
||||||
"eslint": "^8.39.0",
|
"eslint": "^8.39.0",
|
||||||
"jest": "^29.6.2",
|
"jest": "^29.6.2",
|
||||||
|
@ -67,6 +67,7 @@ async function arrDepBoardStaff(CRS) {
|
|||||||
const api = new ldb(ldbsvKey,true);
|
const api = new ldb(ldbsvKey,true);
|
||||||
console.time(`Fetch Staff LDB for ${CRS.toUpperCase()}`);
|
console.time(`Fetch Staff LDB for ${CRS.toUpperCase()}`);
|
||||||
const result = await api.call('GetArrivalDepartureBoardByCRS',options,false,false);
|
const result = await api.call('GetArrivalDepartureBoardByCRS',options,false,false);
|
||||||
|
console.log(`Upstream API Size: ${resultSize}`)
|
||||||
console.timeEnd(`Fetch Staff LDB for ${CRS.toUpperCase()}`)
|
console.timeEnd(`Fetch Staff LDB for ${CRS.toUpperCase()}`)
|
||||||
try {
|
try {
|
||||||
const _staffLdb = staffStationTransform(result)
|
const _staffLdb = staffStationTransform(result)
|
||||||
|
@ -22,6 +22,7 @@ export function transform(input: any): StaffLdb | null {
|
|||||||
console.timeEnd("StaffLdb Transformation")
|
console.timeEnd("StaffLdb Transformation")
|
||||||
return output
|
return output
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.log("utils/translators/ldb/staffLdb.transform: Caught Error")
|
||||||
console.log('Unable to parse data, assuming no data: ' + err)
|
console.log('Unable to parse data, assuming no data: ' + err)
|
||||||
}
|
}
|
||||||
console.timeEnd("StaffLdb Transformation")
|
console.timeEnd("StaffLdb Transformation")
|
||||||
@ -32,20 +33,23 @@ function transformDateTime(input: string): Date {
|
|||||||
return new Date(input)
|
return new Date(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
function transformNrcc(input: any): NrccMessage[] {
|
function transformNrcc(input: any): NrccMessage[] | undefined {
|
||||||
let output: NrccMessage[] = []
|
let output: NrccMessage[] = []
|
||||||
let messages = input
|
let messages = input
|
||||||
if (!Array.isArray(input?.message)) {
|
if (!Array.isArray(input?.message)) {
|
||||||
messages = [input?.message]
|
messages = [input?.message]
|
||||||
}
|
}
|
||||||
for (const item of messages) {
|
if (messages.length) {
|
||||||
let message: NrccMessage = {
|
for (const item of messages) {
|
||||||
severity: item?.severity,
|
let message: NrccMessage = {
|
||||||
xhtmlMessage: removeNewlineAndPTag(item?.xhtmlMessage)
|
severity: item?.severity,
|
||||||
|
xhtmlMessage: removeNewlineAndPTag(item?.xhtmlMessage)
|
||||||
|
}
|
||||||
|
output.push(message)
|
||||||
}
|
}
|
||||||
output.push(message)
|
return output
|
||||||
}
|
}
|
||||||
return output
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
function transformTrainServices(input: any): TrainServices[] {
|
function transformTrainServices(input: any): TrainServices[] {
|
||||||
@ -95,8 +99,7 @@ function transformLocation(input: any): ServiceLocation[] {
|
|||||||
}
|
}
|
||||||
for (const item of locations) {
|
for (const item of locations) {
|
||||||
const location: ServiceLocation = {
|
const location: ServiceLocation = {
|
||||||
tiploc: item?.tiploc,
|
tiploc: item?.tiploc
|
||||||
name: item?.locationName
|
|
||||||
}
|
}
|
||||||
if (item?.via) {
|
if (item?.via) {
|
||||||
location.via = item.via
|
location.via = item.via
|
||||||
|
@ -28,14 +28,12 @@ export const outputs: StaffLdb[] = [
|
|||||||
length: 10,
|
length: 10,
|
||||||
origin: [
|
origin: [
|
||||||
{
|
{
|
||||||
tiploc: "PLYMTH",
|
tiploc: "PLYMTH"
|
||||||
name: "Plymouth"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
destination: [
|
destination: [
|
||||||
{
|
{
|
||||||
tiploc: "BHAMNWS",
|
tiploc: "BHAMNWS"
|
||||||
name: "Birmingham New Street"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user