Fix bug where empty input to transform function does not return null

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-09-11 20:53:29 +01:00
parent b61851e122
commit 843a6cad97

View File

@ -16,7 +16,7 @@ export function transform(input: any): StaffLdb | null {
try {
output = {
generatedAt: transformDateTime(data?.generatedAt) || new Date(),
locationName: data?.locationName || "Not Found",
locationName: data?.locationName || 'Not Found',
stationManagerCode: data?.stationManagerCode || "UK",
nrccMessages: transformNrcc(data?.nrccMessages) || undefined,
trainServices: transformTrainServices(data?.trainServices) || undefined,
@ -24,7 +24,9 @@ export function transform(input: any): StaffLdb | null {
ferryServices: transformTrainServices(data?.ferryServices) || undefined,
};
console.timeEnd("StaffLdb Transformation");
if (output.locationName !== 'Not Found') {
return output;
}
} catch (err) {
console.log("utils/translators/ldb/staffLdb.transform: Caught Error");
console.log("Unable to parse data, assuming no data: " + err);