introduce an endpoint and service to update the active runway and arrival mode

This commit is contained in:
Sven Czarnian
2022-10-25 08:26:39 +02:00
parent 71589fe1b4
commit abe73cdd8b
3 changed files with 77 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ import {
Controller,
Get,
Delete,
Patch,
Post,
Query,
HttpException,
@@ -27,6 +28,7 @@ import { WaypointDto } from '../generic/dto/waypoint.dto';
import { Coordinate } from '../generic/models/coordinate.model';
import { CoordinateDto } from '../generic/dto/coordinate.dto';
import { WaypointConverter } from '../generic/converters';
import { ActiveRunwaysDto } from './dto/activerunways.dto';
@Controller('airport')
export class AirportController {
@@ -317,4 +319,38 @@ export class AirportController {
await this.airportService.deleteAirport(icao);
});
}
@Patch('/activateRunways')
@ApiBody({
description: 'The airport definition',
type: ActiveRunwaysDto,
})
@ApiResponse({
status: 200,
description: 'The active runways are set',
})
@ApiResponse({
status: 404,
description: 'The airport or the runways are not found',
})
@ApiResponse({
status: 422,
description: 'The arrival mode is invalid',
})
async activeRunways(
@Body('runways') runways: ActiveRunwaysDto,
): Promise<void> {
if (runways.mode !== 'STAGGERED' && runways.mode !== 'IPA') {
throw new HttpException(
'Invalid arrival mode',
HttpStatus.UNPROCESSABLE_ENTITY,
);
}
await this.airportService.activateRunways(runways).then((updated) => {
if (!updated) {
throw new HttpException('Airport not found', HttpStatus.NOT_FOUND);
}
});
}
}