introduce an endpoint and service to update the active runway and arrival mode
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
|||||||
Controller,
|
Controller,
|
||||||
Get,
|
Get,
|
||||||
Delete,
|
Delete,
|
||||||
|
Patch,
|
||||||
Post,
|
Post,
|
||||||
Query,
|
Query,
|
||||||
HttpException,
|
HttpException,
|
||||||
@@ -27,6 +28,7 @@ import { WaypointDto } from '../generic/dto/waypoint.dto';
|
|||||||
import { Coordinate } from '../generic/models/coordinate.model';
|
import { Coordinate } from '../generic/models/coordinate.model';
|
||||||
import { CoordinateDto } from '../generic/dto/coordinate.dto';
|
import { CoordinateDto } from '../generic/dto/coordinate.dto';
|
||||||
import { WaypointConverter } from '../generic/converters';
|
import { WaypointConverter } from '../generic/converters';
|
||||||
|
import { ActiveRunwaysDto } from './dto/activerunways.dto';
|
||||||
|
|
||||||
@Controller('airport')
|
@Controller('airport')
|
||||||
export class AirportController {
|
export class AirportController {
|
||||||
@@ -317,4 +319,38 @@ export class AirportController {
|
|||||||
await this.airportService.deleteAirport(icao);
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { InjectModel } from '@nestjs/mongoose';
|
import { InjectModel } from '@nestjs/mongoose';
|
||||||
import { Model } from 'mongoose';
|
import { Model } from 'mongoose';
|
||||||
|
import { ActiveRunwaysDto } from './dto/activerunways.dto';
|
||||||
import { Airport, AirportDocument } from './models/airport.model';
|
import { Airport, AirportDocument } from './models/airport.model';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -57,4 +58,17 @@ export class AirportService {
|
|||||||
async deleteAirport(icao: string): Promise<void> {
|
async deleteAirport(icao: string): Promise<void> {
|
||||||
this.airportModel.deleteOne({ icao });
|
this.airportModel.deleteOne({ icao });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async activateRunways(runways: ActiveRunwaysDto): Promise<boolean> {
|
||||||
|
return this.airportExists(runways.icao).then(async (exists) => {
|
||||||
|
if (exists) {
|
||||||
|
await this.airportModel.findOneAndUpdate(
|
||||||
|
{ icao: runways.icao },
|
||||||
|
{ activeRunways: runways.runways, arrivalMode: runways.mode },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return exists;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
27
src/airport/dto/activerunways.dto.ts
Normal file
27
src/airport/dto/activerunways.dto.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { IsNotEmpty, IsOptional } from 'class-validator';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { ConstraintDto } from './constraint.dto';
|
||||||
|
import { WaypointDto } from '../../generic/dto/waypoint.dto';
|
||||||
|
|
||||||
|
export class ActiveRunwaysDto {
|
||||||
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The ICAO code of the airport',
|
||||||
|
example: 'EDDB',
|
||||||
|
})
|
||||||
|
icao: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The arrival mode (possible: STAGGERED, IPA)',
|
||||||
|
example: 'IPA',
|
||||||
|
})
|
||||||
|
mode: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The active runways',
|
||||||
|
example: '["25L", "25R"]',
|
||||||
|
})
|
||||||
|
runways: string[];
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user