From 68207d1e5e28d6c4809e86af2788386b899381f6 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sat, 5 Aug 2023 01:04:41 +0100 Subject: [PATCH] Add calculateLength() code Signed-off-by: Fred Boniface --- src/utils/translators/ldb/staffStation.ts | 10 +++++++++- test/utils/translators/ldb/staffStation.utils.test.ts | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/utils/translators/ldb/staffStation.ts b/src/utils/translators/ldb/staffStation.ts index 3e3b5df..c30513b 100644 --- a/src/utils/translators/ldb/staffStation.ts +++ b/src/utils/translators/ldb/staffStation.ts @@ -105,7 +105,15 @@ function transformLocation(input: any): ServiceLocation[] { } function calculateLength(input: TrainServices): number | undefined { - console.log(input); + let length: number; + if (input?.length) { + length = input.length + return length + } + if (input?.formation?.coaches?.coach) { + length = input.formation.coaches.coach.length + return length + } return undefined } diff --git a/test/utils/translators/ldb/staffStation.utils.test.ts b/test/utils/translators/ldb/staffStation.utils.test.ts index 9eb5eef..4f839f6 100644 --- a/test/utils/translators/ldb/staffStation.utils.test.ts +++ b/test/utils/translators/ldb/staffStation.utils.test.ts @@ -19,3 +19,5 @@ describe('transform', () => { }); } }); + +// Write test for calculateLength(input: TrainServices): number | undefined \ No newline at end of file