move generic models and DTOs to the root folder and split waypoint and coordinate
This commit is contained in:
		| @@ -22,8 +22,10 @@ import { Assignment } from './models/assignment.model'; | ||||
| import { Constraint } from './models/constraint.model'; | ||||
| import { Planning } from './models/planning.model'; | ||||
| import { RunwaySpacing } from './models/runwayspacing.model'; | ||||
| import { Waypoint } from './models/waypoint.model'; | ||||
| import { WaypointDto } from './dto/waypoint.dto'; | ||||
| import { Waypoint } from '../models/waypoint.model'; | ||||
| import { WaypointDto } from '../dto/waypoint.dto'; | ||||
| import { Coordinate } from 'src/models/coordinate.model'; | ||||
| import { CoordinateDto } from 'src/dto/coordinate.dto'; | ||||
|  | ||||
| @Controller('airport') | ||||
| export class AirportController { | ||||
| @@ -55,29 +57,33 @@ export class AirportController { | ||||
|     return retval; | ||||
|   } | ||||
|  | ||||
|   private static convertWaypoint<T>(waypoint: Waypoint | WaypointDto): T { | ||||
|   private static convertCoordinate<T>( | ||||
|     coordinate: Coordinate | CoordinateDto, | ||||
|   ): T { | ||||
|     return { | ||||
|       identifier: waypoint.identifier, | ||||
|       latitude: waypoint.latitude, | ||||
|       longitude: waypoint.longitude, | ||||
|       latitude: coordinate.latitude, | ||||
|       longitude: coordinate.longitude, | ||||
|     } as T; | ||||
|   } | ||||
|  | ||||
|   private static convertWaypoints<T>( | ||||
|   private static convertWaypoint<T, C>(waypoint: Waypoint | WaypointDto): T { | ||||
|     return { | ||||
|       identifier: waypoint.identifier, | ||||
|       coordinate: AirportController.convertCoordinate<C>(waypoint.coordinate), | ||||
|     } as T; | ||||
|   } | ||||
|  | ||||
|   private static convertWaypoints<T, C>( | ||||
|     waypoints: Waypoint[] | WaypointDto[], | ||||
|   ): T[] { | ||||
|     const retval: T[] = []; | ||||
|     waypoints.forEach((waypoint) => | ||||
|       retval.push({ | ||||
|         identifier: waypoint.identifier, | ||||
|         latitude: waypoint.latitude, | ||||
|         longitude: waypoint.longitude, | ||||
|       } as T), | ||||
|       retval.push(AirportController.convertWaypoint<T, C>(waypoint)), | ||||
|     ); | ||||
|     return retval; | ||||
|   } | ||||
|  | ||||
|   private static convertArrivalRoutes<T, C, W>( | ||||
|   private static convertArrivalRoutes<T, C, W, WC>( | ||||
|     routes: ArrivalRoute[] | ArrivalRouteDto[], | ||||
|   ): T[] { | ||||
|     const retval: T[] = []; | ||||
| @@ -85,7 +91,7 @@ export class AirportController { | ||||
|       retval.push({ | ||||
|         arrival: route.runway, | ||||
|         runway: route.runway, | ||||
|         waypoints: AirportController.convertWaypoints<W>(route.waypoints), | ||||
|         waypoints: AirportController.convertWaypoints<W, WC>(route.waypoints), | ||||
|         constraints: AirportController.convertConstraints<C>(route.constraints), | ||||
|       } as T), | ||||
|     ); | ||||
| @@ -140,7 +146,7 @@ export class AirportController { | ||||
|  | ||||
|     return { | ||||
|       icao: airport.icao, | ||||
|       location: AirportController.convertWaypoint<WaypointDto>( | ||||
|       location: AirportController.convertWaypoint<WaypointDto, CoordinateDto>( | ||||
|         airport.location, | ||||
|       ), | ||||
|       elevation: airport.elevation, | ||||
| @@ -150,7 +156,8 @@ export class AirportController { | ||||
|       arrivalRoutes: AirportController.convertArrivalRoutes< | ||||
|         ArrivalRouteDto, | ||||
|         ConstraintDto, | ||||
|         WaypointDto | ||||
|         WaypointDto, | ||||
|         CoordinateDto | ||||
|       >(airport.arrivalRoutes), | ||||
|       spacings: AirportController.convertRunwaySpacings<RunwaySpacingDto>( | ||||
|         airport.spacings, | ||||
| @@ -166,7 +173,9 @@ export class AirportController { | ||||
|  | ||||
|     return { | ||||
|       icao: airport.icao, | ||||
|       location: AirportController.convertWaypoint<Waypoint>(airport.location), | ||||
|       location: AirportController.convertWaypoint<Waypoint, Coordinate>( | ||||
|         airport.location, | ||||
|       ), | ||||
|       elevation: airport.elevation, | ||||
|       upperConstraints: AirportController.convertConstraints<Constraint>( | ||||
|         airport.upperConstraints, | ||||
| @@ -174,7 +183,8 @@ export class AirportController { | ||||
|       arrivalRoutes: AirportController.convertArrivalRoutes< | ||||
|         ArrivalRoute, | ||||
|         Constraint, | ||||
|         Waypoint | ||||
|         Waypoint, | ||||
|         Coordinate | ||||
|       >(airport.arrivalRoutes), | ||||
|       spacings: AirportController.convertRunwaySpacings<RunwaySpacing>( | ||||
|         airport.spacings, | ||||
|   | ||||
| @@ -4,7 +4,7 @@ import { ConstraintDto } from './constraint.dto'; | ||||
| import { ArrivalRouteDto } from './arrivalroute.dto'; | ||||
| import { RunwaySpacingDto } from './runwayspacing.dto'; | ||||
| import { PlanningDto } from './planning.dto'; | ||||
| import { WaypointDto } from './waypoint.dto'; | ||||
| import { WaypointDto } from '../../dto/waypoint.dto'; | ||||
|  | ||||
| export class AirportDto { | ||||
|   @IsNotEmpty() | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| import { IsNotEmpty, IsOptional } from 'class-validator'; | ||||
| import { ApiProperty } from '@nestjs/swagger'; | ||||
| import { ConstraintDto } from './constraint.dto'; | ||||
| import { WaypointDto } from './waypoint.dto'; | ||||
| import { WaypointDto } from '../../dto/waypoint.dto'; | ||||
|  | ||||
| export class ArrivalRouteDto { | ||||
|   @IsNotEmpty() | ||||
|   | ||||
| @@ -4,7 +4,7 @@ import { ArrivalRoute, ArrivalRouteSchema } from './arrivalroute.model'; | ||||
| import { Constraint, ConstraintSchema } from './constraint.model'; | ||||
| import { Planning, PlanningSchema } from './planning.model'; | ||||
| import { RunwaySpacing, RunwaySpacingSchema } from './runwayspacing.model'; | ||||
| import { Waypoint } from './waypoint.model'; | ||||
| import { Waypoint } from '../../models/waypoint.model'; | ||||
|  | ||||
| export type AirportDocument = Airport & Document; | ||||
|  | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; | ||||
| import { Document } from 'mongoose'; | ||||
| import { Constraint, ConstraintSchema } from './constraint.model'; | ||||
| import { Waypoint, WaypointSchema } from './waypoint.model'; | ||||
| import { Waypoint, WaypointSchema } from '../../models/waypoint.model'; | ||||
|  | ||||
| export type ArrivalRouteDocument = ArrivalRoute & Document; | ||||
|  | ||||
|   | ||||
| @@ -1,14 +1,7 @@ | ||||
| import { IsNotEmpty, IsLatitude, IsLongitude } from 'class-validator'; | ||||
| import { ApiProperty } from '@nestjs/swagger'; | ||||
| 
 | ||||
| export class WaypointDto { | ||||
|   @IsNotEmpty() | ||||
|   @ApiProperty({ | ||||
|     description: 'The unique waypoint code', | ||||
|     example: 'KETAP', | ||||
|   }) | ||||
|   identifier: string; | ||||
| 
 | ||||
| export class CoordinateDto { | ||||
|   @IsNotEmpty() | ||||
|   @ApiProperty({ | ||||
|     description: 'The latitudinal component', | ||||
							
								
								
									
										19
									
								
								src/dto/waypoint.dto.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/dto/waypoint.dto.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| import { IsNotEmpty } from 'class-validator'; | ||||
| import { ApiProperty } from '@nestjs/swagger'; | ||||
| import { CoordinateDto } from './coordinate.dto'; | ||||
|  | ||||
| export class WaypointDto { | ||||
|   @IsNotEmpty() | ||||
|   @ApiProperty({ | ||||
|     description: 'The unique waypoint code', | ||||
|     example: 'KETAP', | ||||
|   }) | ||||
|   identifier: string; | ||||
|  | ||||
|   @IsNotEmpty() | ||||
|   @ApiProperty({ | ||||
|     description: 'The latitudinal component', | ||||
|     example: 42.8402, | ||||
|   }) | ||||
|   coordinate: CoordinateDto; | ||||
| } | ||||
							
								
								
									
										21
									
								
								src/models/coordinate.model.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/models/coordinate.model.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; | ||||
| import { Document } from 'mongoose'; | ||||
|  | ||||
| export type CoordinateDocument = Coordinate & Document; | ||||
|  | ||||
| @Schema() | ||||
| export class Coordinate { | ||||
|   @Prop({ | ||||
|     required: true, | ||||
|     type: Number, | ||||
|   }) | ||||
|   latitude: number; | ||||
|  | ||||
|   @Prop({ | ||||
|     required: true, | ||||
|     type: Number, | ||||
|   }) | ||||
|   longitude: number; | ||||
| } | ||||
|  | ||||
| export const CoordinateSchema = SchemaFactory.createForClass(Coordinate); | ||||
| @@ -1,5 +1,6 @@ | ||||
| import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; | ||||
| import { Document } from 'mongoose'; | ||||
| import { Coordinate, CoordinateSchema } from './coordinate.model'; | ||||
| 
 | ||||
| export type WaypointDocument = Waypoint & Document; | ||||
| 
 | ||||
| @@ -13,15 +14,9 @@ export class Waypoint { | ||||
| 
 | ||||
|   @Prop({ | ||||
|     required: true, | ||||
|     type: Number, | ||||
|     type: CoordinateSchema, | ||||
|   }) | ||||
|   latitude: number; | ||||
| 
 | ||||
|   @Prop({ | ||||
|     required: true, | ||||
|     type: Number, | ||||
|   }) | ||||
|   longitude: number; | ||||
|   coordinate: Coordinate; | ||||
| } | ||||
| 
 | ||||
| export const WaypointSchema = SchemaFactory.createForClass(Waypoint); | ||||
		Reference in New Issue
	
	Block a user