fix wrong enum values and validate the inputs in the endpoints
This commit is contained in:
		| @@ -24,7 +24,7 @@ export class InboundDto { | ||||
|   @IsNotEmpty() | ||||
|   @ApiProperty({ | ||||
|     description: | ||||
|       'The reported controller level (possible: UNK, DEL, GRD, TWR, APP, DEP, CTR)', | ||||
|       'The reported controller level (possible: UNK, DEL, GND, TWR, APP, DEP, CTR)', | ||||
|     example: 'EDDB', | ||||
|   }) | ||||
|   @Length(3) | ||||
|   | ||||
| @@ -29,6 +29,11 @@ import { Inbound } from './models/inbound.model'; | ||||
| import { Planning } from './models/planning.model'; | ||||
| import { PredictedWaypoint } from './models/predictedwaypoint.model'; | ||||
|  | ||||
| const AllowedWtcs = ['L', 'M', 'H', 'J']; | ||||
| const AllowedWakeRecats = ['A', 'B', 'C', 'D', 'E', 'F']; | ||||
| const AllowedEngineTypes = ['ELECTRIC', 'TURBOPROP', 'JET']; | ||||
| const AllowedReporterTypes = ['UNK', 'DEL', 'GND', 'TWR', 'APP', 'DEP', 'CTR']; | ||||
|  | ||||
| @Controller('inbound') | ||||
| export class InboundController { | ||||
|   constructor( | ||||
| @@ -200,7 +205,62 @@ export class InboundController { | ||||
|     status: 404, | ||||
|     description: 'The destination airport is unknown', | ||||
|   }) | ||||
|   @ApiResponse({ | ||||
|     status: 422, | ||||
|     description: 'The WTC is invalid', | ||||
|   }) | ||||
|   @ApiResponse({ | ||||
|     status: 422, | ||||
|     description: 'The wake recat is invalid', | ||||
|   }) | ||||
|   @ApiResponse({ | ||||
|     status: 422, | ||||
|     description: 'The engine type is invalid', | ||||
|   }) | ||||
|   @ApiResponse({ | ||||
|     status: 422, | ||||
|     description: 'The reporter is invalid', | ||||
|   }) | ||||
|   async insert(inbound: InboundDto): Promise<boolean> { | ||||
|     if ( | ||||
|       AllowedWtcs.find((element) => element === inbound.aircraft.wtc) === | ||||
|       undefined | ||||
|     ) { | ||||
|       throw new HttpException( | ||||
|         'The WTC is invalid', | ||||
|         HttpStatus.UNPROCESSABLE_ENTITY, | ||||
|       ); | ||||
|     } | ||||
|     if ( | ||||
|       AllowedWakeRecats.find( | ||||
|         (element) => element === inbound.aircraft.wakeRecat, | ||||
|       ) === undefined | ||||
|     ) { | ||||
|       throw new HttpException( | ||||
|         'The wake recat is invalid', | ||||
|         HttpStatus.UNPROCESSABLE_ENTITY, | ||||
|       ); | ||||
|     } | ||||
|     if ( | ||||
|       AllowedEngineTypes.find( | ||||
|         (element) => element === inbound.aircraft.engineType, | ||||
|       ) === undefined | ||||
|     ) { | ||||
|       throw new HttpException( | ||||
|         'The engine type is invalid', | ||||
|         HttpStatus.UNPROCESSABLE_ENTITY, | ||||
|       ); | ||||
|     } | ||||
|     if ( | ||||
|       AllowedReporterTypes.find((element) => element === inbound.reporter) === | ||||
|       undefined | ||||
|     ) { | ||||
|       throw new HttpException( | ||||
|         'The reporter type is invalid', | ||||
|         HttpStatus.UNPROCESSABLE_ENTITY, | ||||
|       ); | ||||
|     } | ||||
|  | ||||
|     return this.airportService | ||||
|       .airport(inbound.destination) | ||||
|       .then(async (airport) => { | ||||
|   | ||||
| @@ -14,7 +14,7 @@ export class Aircraft { | ||||
|   @Prop({ | ||||
|     required: true, | ||||
|     type: String, | ||||
|     enum: ['L', 'M', 'H', 'S'], | ||||
|     enum: ['L', 'M', 'H', 'J'], | ||||
|   }) | ||||
|   wtc: string; | ||||
|  | ||||
|   | ||||
| @@ -29,7 +29,7 @@ export class Inbound { | ||||
|   @Prop({ | ||||
|     required: true, | ||||
|     type: String, | ||||
|     enum: ['UNK', 'DEL', 'GRD', 'TWR', 'APP', 'DEP', 'CTR'], | ||||
|     enum: ['UNK', 'DEL', 'GND', 'TWR', 'APP', 'DEP', 'CTR'], | ||||
|   }) | ||||
|   reporter: string; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user