newStaffLDB-API #48

Merged
fred.boniface merged 85 commits from newStaffLDB-API into main 2023-10-03 21:35:03 +01:00
1 changed files with 11 additions and 8 deletions
Showing only changes of commit 6d4e862313 - Show all commits

View File

@ -8,6 +8,8 @@ import type {
import { tz } from "moment-timezone";
import { removeNewlineAndPTag } from "../../newSanitizer";
import { logger } from "../../logger.utils";
/// I do not yet have a type defined for any of the input object
export function transform(input: any): StaffLdb | null {
console.time("StaffLdb Transformation");
@ -28,20 +30,19 @@ export function transform(input: any): StaffLdb | null {
return output;
}
} catch (err) {
console.log("utils/translators/ldb/staffLdb.transform: Caught Error");
console.log("Unable to parse data, assuming no data. ERR: " + err);
logger.error(err, "utils/translators/ldb/staffLdb.transform");
}
console.timeEnd("StaffLdb Transformation");
return null;
}
function transformDateTime(input: string): Date {
//console.log("Transform Date Time Running")
logger.trace("utils/translators/ldb/staffLdb.transformDateTime: Running");
return new Date(input);
}
function transformNrcc(input: any): NrccMessage[] | undefined {
//console.log("Transform Nrcc Running")
logger.trace("utils/translators/ldb/staffLdb.transformNrcc: Running");
if (input === undefined) {
return input;
}
@ -64,7 +65,7 @@ function transformNrcc(input: any): NrccMessage[] | undefined {
}
function transformTrainServices(input: any): TrainServices[] {
//console.log("Transform Train Services Running")
logger.trace("utils/translators/ldb/staffLdb.transformTrainServices: Running");
let services: any = input?.service;
let output: TrainServices[] = [];
if (services === undefined) {
@ -107,6 +108,7 @@ function transformTrainServices(input: any): TrainServices[] {
}
function checkIsSupressed(service: TrainServices): string | undefined {
logger.trace("utils/translators/ldb/staffStation.checkIsSupressed: Running");
if (service.serviceIsSupressed === "true" || service.isNonPublic === "true") {
return "true";
} else {
@ -115,7 +117,7 @@ function checkIsSupressed(service: TrainServices): string | undefined {
}
function transformLocation(input: any): ServiceLocation[] {
//console.log("Transform Location Running")
logger.trace("utils/translators/ldb/staffStation.transformLocation: Running");
let output: ServiceLocation[] = [];
let locations: any[] = input.location;
if (!Array.isArray(input.location)) {
@ -134,7 +136,7 @@ function transformLocation(input: any): ServiceLocation[] {
}
export function calculateLength(input: any): number | undefined {
//console.log("Calculate Length Running")
logger.trace("utils/translators/ldb/staffStation.calculateLength: Running");
let length: number;
if (input?.length) {
length = input.length;
@ -148,7 +150,7 @@ export function calculateLength(input: any): number | undefined {
}
function transformUnspecifiedDateTime(input: string): Date | undefined {
//console.log("Transform Unspecified Date Time Running")
logger.trace("utils/translators/ldb/staffStation.transformUnspecifiedDateTime: Running");
if (!input) {
return undefined;
}
@ -157,6 +159,7 @@ function transformUnspecifiedDateTime(input: string): Date | undefined {
}
function parseTimes(service: TrainServices) {
logger.trace("utils/translators/ldb/staffStation.parseTimes: Running");
let { sta, eta, ata, std, etd, atd } = Object.fromEntries(
Object.entries(service).map(([key, value]) => [
key,