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