From 4b218592422d18741bd098f488bce2b91fe53cff Mon Sep 17 00:00:00 2001 From: Sven Czarnian Date: Sun, 23 Oct 2022 23:10:33 +0200 Subject: [PATCH] prepare the inbound to calculate the different parameters --- src/inbound/inbound.controller.ts | 42 +++++++++++++++---- src/inbound/models/controllerinput.model.ts | 9 ++-- src/inbound/models/predictedwaypoint.model.ts | 4 -- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/inbound/inbound.controller.ts b/src/inbound/inbound.controller.ts index d30bd9b..f08ca46 100644 --- a/src/inbound/inbound.controller.ts +++ b/src/inbound/inbound.controller.ts @@ -1,5 +1,4 @@ import { - Body, Controller, Get, Delete, @@ -44,15 +43,44 @@ export class InboundController { } as T; } + private static waypointsDtoToPredictedWaypoints( + waypoints: WaypointDto[], + ): PredictedWaypoint[] { + const retval: PredictedWaypoint[] = []; + waypoints.forEach((waypoint) => + retval.push({ + waypoint: WaypointConverter.convert(waypoint), + altitude: undefined, + indicatedAirspeed: undefined, + groundspeed: undefined, + plannedOverheadTime: undefined, + }), + ); + return retval; + } + private static convertControllerInput( input: ControllerInput | ControllerInputDto, ): T { - return { - reportedTime: input.reportedTime, - remainingRoute: WaypointConverter.convertList(input.remainingRoute), - requestedRunway: input.requestedRunway, - plannedStand: input.plannedStand, - } as T; + if (input instanceof ControllerInputDto) { + return { + reportedTime: input.reportedTime, + remainingRoute: InboundController.waypointsDtoToPredictedWaypoints( + input.remainingRoute, + ), + requestedRunway: input.requestedRunway, + plannedStand: input.plannedStand, + } as T; + } else { + return { + reportedTime: input.reportedTime, + remainingRoute: InboundController.convertPredictedWaypoints( + input.remainingRoute, + ), + requestedRunway: input.requestedRunway, + plannedStand: input.plannedStand, + } as T; + } } private static convertFlightState(input: FlightState | FlightStateDto): T { diff --git a/src/inbound/models/controllerinput.model.ts b/src/inbound/models/controllerinput.model.ts index 5cddaa5..53d70b7 100644 --- a/src/inbound/models/controllerinput.model.ts +++ b/src/inbound/models/controllerinput.model.ts @@ -1,6 +1,9 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { Document } from 'mongoose'; -import { Waypoint, WaypointSchema } from 'src/generic/models/waypoint.model'; +import { + PredictedWaypoint, + PredictedWaypointSchema, +} from './predictedwaypoint.model'; export type ControllerInputDocument = ControllerInput & Document; @@ -13,9 +16,9 @@ export class ControllerInput { @Prop({ required: true, - type: [WaypointSchema], + type: [PredictedWaypointSchema], }) - remainingRoute: Waypoint[]; + remainingRoute: PredictedWaypoint[]; @Prop({ type: String, diff --git a/src/inbound/models/predictedwaypoint.model.ts b/src/inbound/models/predictedwaypoint.model.ts index 4be31af..09a7c7d 100644 --- a/src/inbound/models/predictedwaypoint.model.ts +++ b/src/inbound/models/predictedwaypoint.model.ts @@ -13,25 +13,21 @@ export class PredictedWaypoint { waypoint: Waypoint; @Prop({ - required: true, type: Number, }) altitude: number; @Prop({ - required: true, type: Number, }) indicatedAirspeed: number; @Prop({ - required: true, type: Number, }) groundspeed: number; @Prop({ - required: true, type: String, }) plannedOverheadTime: string;