newStaffLDB-API #48

Merged
fred.boniface merged 85 commits from newStaffLDB-API into main 2023-10-03 21:35:03 +01:00
Showing only changes of commit 6d4e862313 - Show all commits

View File

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