update the weather data
This commit is contained in:
		| @@ -8,10 +8,13 @@ import { | |||||||
|   HttpStatus, |   HttpStatus, | ||||||
| } from '@nestjs/common'; | } from '@nestjs/common'; | ||||||
| import { ApiBody, ApiQuery, ApiResponse } from '@nestjs/swagger'; | import { ApiBody, ApiQuery, ApiResponse } from '@nestjs/swagger'; | ||||||
|  | import { WGS84 } from '../math'; | ||||||
|  | import { WeatherService } from 'src/weather/weather.service'; | ||||||
| import { AirportService } from '../airport/airport.service'; | import { AirportService } from '../airport/airport.service'; | ||||||
| import { CoordinateConverter, WaypointConverter } from '../generic/converters'; | import { CoordinateConverter, WaypointConverter } from '../generic/converters'; | ||||||
| import { CoordinateDto } from '../generic/dto/coordinate.dto'; | import { CoordinateDto } from '../generic/dto/coordinate.dto'; | ||||||
| import { WaypointDto } from '../generic/dto/waypoint.dto'; | import { WaypointDto } from '../generic/dto/waypoint.dto'; | ||||||
|  | import { PerformanceService } from '../performance/performance.service'; | ||||||
| import { AircraftDto } from './dto/aircraft.dto'; | import { AircraftDto } from './dto/aircraft.dto'; | ||||||
| import { ControllerInputDto } from './dto/controllerinput.dto'; | import { ControllerInputDto } from './dto/controllerinput.dto'; | ||||||
| import { FlightStateDto } from './dto/flightstate.dto'; | import { FlightStateDto } from './dto/flightstate.dto'; | ||||||
| @@ -31,6 +34,8 @@ export class InboundController { | |||||||
|   constructor( |   constructor( | ||||||
|     private readonly inboundService: InboundService, |     private readonly inboundService: InboundService, | ||||||
|     private readonly airportService: AirportService, |     private readonly airportService: AirportService, | ||||||
|  |     private readonly performanceService: PerformanceService, | ||||||
|  |     private readonly weatherService: WeatherService, | ||||||
|   ) {} |   ) {} | ||||||
|  |  | ||||||
|   private static convertAircraft<T>(aircraft: Aircraft | AircraftDto): T { |   private static convertAircraft<T>(aircraft: Aircraft | AircraftDto): T { | ||||||
| @@ -196,24 +201,56 @@ export class InboundController { | |||||||
|     description: 'The destination airport is unknown', |     description: 'The destination airport is unknown', | ||||||
|   }) |   }) | ||||||
|   async insert(inbound: InboundDto): Promise<boolean> { |   async insert(inbound: InboundDto): Promise<boolean> { | ||||||
|     return this.airportService.airport(inbound.destination).then((airport) => { |     return this.airportService | ||||||
|       if (!airport) { |       .airport(inbound.destination) | ||||||
|         throw new HttpException('Airport not found', HttpStatus.NOT_FOUND); |       .then(async (airport) => { | ||||||
|       } |         if (!airport) { | ||||||
|  |           throw new HttpException('Airport not found', HttpStatus.NOT_FOUND); | ||||||
|  |         } | ||||||
|  |  | ||||||
|       return this.inboundService |         // update the weather data | ||||||
|         .callsignKnown(inbound.callsign) |         if (inbound.controllerData.remainingRoute.length >= 1) { | ||||||
|         .then((known) => { |           await this.weatherService.update( | ||||||
|           const internalInbound = |             inbound.destination, | ||||||
|             InboundController.convertInboundDtoInbound(inbound); |             inbound.controllerData.remainingRoute[0].identifier, | ||||||
|  |             WGS84.distance( | ||||||
|  |               { | ||||||
|  |                 lat: inbound.flightState.position.latitude, | ||||||
|  |                 lon: inbound.flightState.position.longitude, | ||||||
|  |               }, | ||||||
|  |               { | ||||||
|  |                 lat: inbound.controllerData.remainingRoute[0].coordinate | ||||||
|  |                   .latitude, | ||||||
|  |                 lon: inbound.controllerData.remainingRoute[0].coordinate | ||||||
|  |                   .longitude, | ||||||
|  |               }, | ||||||
|  |             ) * 0.000539957, | ||||||
|  |             inbound.flightState.groundSpeed, | ||||||
|  |             inbound.flightState.heading, | ||||||
|  |             inbound.flightState.groundTrack, | ||||||
|  |             inbound.flightState.altitude, | ||||||
|  |           ); | ||||||
|  |         } | ||||||
|  |  | ||||||
|           if (known) { |         const performance = await this.performanceService.findAircraft( | ||||||
|             return this.inboundService.update(internalInbound); |           inbound.aircraft.type, | ||||||
|           } else { |           inbound.aircraft.wtc, | ||||||
|  |           inbound.aircraft.engineCount, | ||||||
|  |         ); | ||||||
|  |         const internalInbound = | ||||||
|  |           InboundController.convertInboundDtoInbound(inbound); | ||||||
|  |  | ||||||
|  |         // TODO calculate remaining route predictions | ||||||
|  |  | ||||||
|  |         return this.inboundService | ||||||
|  |           .callsignKnown(inbound.callsign) | ||||||
|  |           .then((known) => { | ||||||
|  |             if (known) { | ||||||
|  |               return this.inboundService.update(internalInbound); | ||||||
|  |             } | ||||||
|             return this.inboundService.add(internalInbound); |             return this.inboundService.add(internalInbound); | ||||||
|           } |           }); | ||||||
|         }); |       }); | ||||||
|     }); |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   @Delete('/remove') |   @Delete('/remove') | ||||||
|   | |||||||
| @@ -4,11 +4,15 @@ import { InboundSchema } from './models/inbound.model'; | |||||||
| import { InboundService } from './inbound.service'; | import { InboundService } from './inbound.service'; | ||||||
| import { InboundController } from './inbound.controller'; | import { InboundController } from './inbound.controller'; | ||||||
| import { AirportModule } from '../airport/airport.module'; | import { AirportModule } from '../airport/airport.module'; | ||||||
|  | import { PerformanceModule } from '../performance/performance.module'; | ||||||
|  | import { WeatherModule } from '../weather/weather.module'; | ||||||
|  |  | ||||||
| @Module({ | @Module({ | ||||||
|   imports: [ |   imports: [ | ||||||
|     MongooseModule.forFeature([{ name: 'inbound', schema: InboundSchema }]), |     MongooseModule.forFeature([{ name: 'inbound', schema: InboundSchema }]), | ||||||
|     AirportModule, |     AirportModule, | ||||||
|  |     PerformanceModule, | ||||||
|  |     WeatherModule, | ||||||
|   ], |   ], | ||||||
|   providers: [InboundService], |   providers: [InboundService], | ||||||
|   controllers: [InboundController], |   controllers: [InboundController], | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user