From edb33153ceb3a1a0b66f5025b265a4a2a95282c6 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Tue, 1 Aug 2023 13:40:04 +0100 Subject: [PATCH] Add translation utility for formatting StaffLDB(Station) Data Signed-off-by: Fred Boniface --- src/utils/translators/ldb/staffStation.ts | 43 +++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/utils/translators/ldb/staffStation.ts diff --git a/src/utils/translators/ldb/staffStation.ts b/src/utils/translators/ldb/staffStation.ts new file mode 100644 index 0000000..d5dd100 --- /dev/null +++ b/src/utils/translators/ldb/staffStation.ts @@ -0,0 +1,43 @@ +export type { StaffLdb, NrccMessage, TrainServices, + ServiceLocation } from '@owlboard/ts-types' + +/// I do not yet have a type defined for any of the input object +export function transform(input: Object): StaffLdb { + let output: StaffLdb + return output +} + +function transformNrcc(input: any): NrccMessage[] { + let output: NrccMessage[] = [] + if (!Array.isArray(input?.message)) { + input.message = [input.message] + } + for (const item of input?.message) { + let message = { + severity: item?.severity, + xhtmlMessage: item?.xhtmlMessage + } + output.push(message) + } + return output +} + +function transformTrainServices(input: Object): TrainServices[] { + let output: TrainServices[] + return output +} + +function transformLocation(input: any): ServiceLocation { + let output: ServiceLocation[] = [] + if (!Array.isArray(input)) { + input = [input] + } + for (const item of input) { + const location: ServiceLocation = { + tiploc: item?.tiploc, + name: item?.locationName + } + output.push(location) + } + return output +} \ No newline at end of file