define a generic folder
This commit is contained in:
@@ -22,10 +22,11 @@ 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 { Coordinate } from 'src/models/coordinate.model';
|
||||
import { CoordinateDto } from 'src/dto/coordinate.dto';
|
||||
import { Waypoint } from '../generic/models/waypoint.model';
|
||||
import { WaypointDto } from '../generic/dto/waypoint.dto';
|
||||
import { Coordinate } from 'src/generic/models/coordinate.model';
|
||||
import { CoordinateDto } from 'src/generic/dto/coordinate.dto';
|
||||
import { WaypointConverter } from 'src/generic/converters';
|
||||
|
||||
@Controller('airport')
|
||||
export class AirportController {
|
||||
@@ -57,32 +58,6 @@ export class AirportController {
|
||||
return retval;
|
||||
}
|
||||
|
||||
private static convertCoordinate<T>(
|
||||
coordinate: Coordinate | CoordinateDto,
|
||||
): T {
|
||||
return {
|
||||
latitude: coordinate.latitude,
|
||||
longitude: coordinate.longitude,
|
||||
} as 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(AirportController.convertWaypoint<T, C>(waypoint)),
|
||||
);
|
||||
return retval;
|
||||
}
|
||||
|
||||
private static convertArrivalRoutes<T, C, W, WC>(
|
||||
routes: ArrivalRoute[] | ArrivalRouteDto[],
|
||||
): T[] {
|
||||
@@ -91,7 +66,7 @@ export class AirportController {
|
||||
retval.push({
|
||||
arrival: route.runway,
|
||||
runway: route.runway,
|
||||
waypoints: AirportController.convertWaypoints<W, WC>(route.waypoints),
|
||||
waypoints: WaypointConverter.convertList<W, WC>(route.waypoints),
|
||||
constraints: AirportController.convertConstraints<C>(route.constraints),
|
||||
} as T),
|
||||
);
|
||||
@@ -146,7 +121,7 @@ export class AirportController {
|
||||
|
||||
return {
|
||||
icao: airport.icao,
|
||||
location: AirportController.convertWaypoint<WaypointDto, CoordinateDto>(
|
||||
location: WaypointConverter.convert<WaypointDto, CoordinateDto>(
|
||||
airport.location,
|
||||
),
|
||||
elevation: airport.elevation,
|
||||
@@ -173,7 +148,7 @@ export class AirportController {
|
||||
|
||||
return {
|
||||
icao: airport.icao,
|
||||
location: AirportController.convertWaypoint<Waypoint, Coordinate>(
|
||||
location: WaypointConverter.convert<Waypoint, Coordinate>(
|
||||
airport.location,
|
||||
),
|
||||
elevation: airport.elevation,
|
||||
|
||||
@@ -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 '../../dto/waypoint.dto';
|
||||
import { WaypointDto } from '../../generic/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 '../../dto/waypoint.dto';
|
||||
import { WaypointDto } from '../../generic/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 '../../models/waypoint.model';
|
||||
import { Waypoint } from '../../generic/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 '../../models/waypoint.model';
|
||||
import { Waypoint, WaypointSchema } from '../../generic/models/waypoint.model';
|
||||
|
||||
export type ArrivalRouteDocument = ArrivalRoute & Document;
|
||||
|
||||
|
||||
11
src/generic/converters/coordinate.ts
Normal file
11
src/generic/converters/coordinate.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { CoordinateDto } from '../dto/coordinate.dto';
|
||||
import { Coordinate } from '../models/coordinate.model';
|
||||
|
||||
export class CoordinateConverter {
|
||||
static convert<T>(coordinate: Coordinate | CoordinateDto): T {
|
||||
return {
|
||||
latitude: coordinate.latitude,
|
||||
longitude: coordinate.longitude,
|
||||
} as T;
|
||||
}
|
||||
}
|
||||
4
src/generic/converters/index.ts
Normal file
4
src/generic/converters/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { CoordinateConverter } from './coordinate';
|
||||
import { WaypointConverter } from './waypoint';
|
||||
|
||||
export { CoordinateConverter, WaypointConverter };
|
||||
20
src/generic/converters/waypoint.ts
Normal file
20
src/generic/converters/waypoint.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { WaypointDto } from '../dto/waypoint.dto';
|
||||
import { Waypoint } from '../models/waypoint.model';
|
||||
import { CoordinateConverter } from './coordinate';
|
||||
|
||||
export class WaypointConverter {
|
||||
static convert<T, C>(waypoint: Waypoint | WaypointDto): T {
|
||||
return {
|
||||
identifier: waypoint.identifier,
|
||||
coordinate: CoordinateConverter.convert<C>(waypoint.coordinate),
|
||||
} as T;
|
||||
}
|
||||
|
||||
static convertList<T, E>(waypoints: Waypoint[] | WaypointDto[]): T[] {
|
||||
const retval: T[] = [];
|
||||
waypoints.forEach((waypoint) =>
|
||||
retval.push(WaypointConverter.convert<T, E>(waypoint)),
|
||||
);
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
Посилання в новій задачі
Block a user