From bb9044698dfd68e754d6149c7dd41ac69a7c35ad Mon Sep 17 00:00:00 2001 From: Sven Czarnian Date: Tue, 1 Nov 2022 02:00:49 +0100 Subject: [PATCH] add some description entries for the UI --- src/airport/airport.controller.ts | 13 +++++++++---- src/airport/airport.service.ts | 15 +++++++++++---- src/airport/dto/airport.dto.ts | 14 ++++++++++++++ src/airport/dto/airportoverview.dto.ts | 25 +++++++++++++++++++++++++ src/airport/models/airport.model.ts | 12 ++++++++++++ 5 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 src/airport/dto/airportoverview.dto.ts diff --git a/src/airport/airport.controller.ts b/src/airport/airport.controller.ts index 64f7f8d..761bbf8 100644 --- a/src/airport/airport.controller.ts +++ b/src/airport/airport.controller.ts @@ -31,6 +31,7 @@ import { CoordinateConverter, WaypointConverter } from '../generic/converters'; import { ActiveRunwaysDto } from './dto/activerunways.dto'; import { Runway } from './models/runway.model'; import { RunwayDto } from './dto/runway.dto'; +import { AirportOverviewDto } from './dto/airportoverview.dto'; @Controller('airport') export class AirportController { @@ -136,6 +137,8 @@ export class AirportController { return { icao: airport.icao, + name: airport.name, + flightInformationRegion: airport.flightInformationRegion, location: WaypointConverter.convert( airport.location, ), @@ -166,6 +169,8 @@ export class AirportController { return { icao: airport.icao, + name: airport.name, + flightInformationRegion: airport.flightInformationRegion, location: WaypointConverter.convert( airport.location, ), @@ -241,14 +246,14 @@ export class AirportController { }); } - @Get('/allCodes') + @Get('/all') @ApiResponse({ status: 200, description: 'All available airports', - type: [String], + type: [AirportOverviewDto], }) - async allCodes(): Promise { - return this.airportService.airportsList(); + async all(): Promise { + return this.airportService.allAirports(); } @Get('/get') diff --git a/src/airport/airport.service.ts b/src/airport/airport.service.ts index 185d783..2f670b7 100644 --- a/src/airport/airport.service.ts +++ b/src/airport/airport.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; import { ActiveRunwaysDto } from './dto/activerunways.dto'; +import { AirportOverviewDto } from './dto/airportoverview.dto'; import { Airport, AirportDocument } from './models/airport.model'; @Injectable() @@ -17,11 +18,17 @@ export class AirportService { .then((response) => response && response.length !== 0); } - async airportsList(): Promise { + async allAirports(): Promise { return this.airportModel.find({}).then((response) => { - const icaoCodes: string[] = []; - response.forEach((airport) => icaoCodes.push(airport.icao)); - return icaoCodes; + const retval: AirportOverviewDto[] = []; + response.forEach((airport) => + retval.push({ + icao: airport.icao, + name: airport.name, + flightInformationRegion: airport.flightInformationRegion, + }), + ); + return retval; }); } diff --git a/src/airport/dto/airport.dto.ts b/src/airport/dto/airport.dto.ts index 5563fac..d0832a3 100644 --- a/src/airport/dto/airport.dto.ts +++ b/src/airport/dto/airport.dto.ts @@ -15,6 +15,20 @@ export class AirportDto { }) icao: string; + @IsNotEmpty() + @ApiProperty({ + description: 'The name of the airport', + example: 'Berlin Brandenburg', + }) + name: string; + + @IsNotEmpty() + @ApiProperty({ + description: 'The flight information region (FIR)', + example: 'FIR Bremen', + }) + flightInformationRegion: string; + @IsNotEmpty() @ApiProperty({ description: 'The airport location', diff --git a/src/airport/dto/airportoverview.dto.ts b/src/airport/dto/airportoverview.dto.ts new file mode 100644 index 0000000..241c73c --- /dev/null +++ b/src/airport/dto/airportoverview.dto.ts @@ -0,0 +1,25 @@ +import { IsNotEmpty } from 'class-validator'; +import { ApiProperty } from '@nestjs/swagger'; + +export class AirportOverviewDto { + @IsNotEmpty() + @ApiProperty({ + description: 'The unique ICAO code', + example: 'EDDB', + }) + icao: string; + + @IsNotEmpty() + @ApiProperty({ + description: 'The name of the airport', + example: 'Berlin Brandenburg', + }) + name: string; + + @IsNotEmpty() + @ApiProperty({ + description: 'The flight information region (FIR)', + example: 'FIR Bremen', + }) + flightInformationRegion: string; +} diff --git a/src/airport/models/airport.model.ts b/src/airport/models/airport.model.ts index 27ea69d..16c5634 100644 --- a/src/airport/models/airport.model.ts +++ b/src/airport/models/airport.model.ts @@ -18,6 +18,18 @@ export class Airport { }) icao: string; + @Prop({ + required: true, + type: String, + }) + name: string; + + @Prop({ + required: true, + type: String, + }) + flightInformationRegion: string; + @Prop({ required: true, type: Waypoint,