validate the airport inputs
This commit is contained in:
@@ -174,6 +174,56 @@ export class AirportController {
|
||||
};
|
||||
}
|
||||
|
||||
private static validateAirportEnums(airport: AirportDto): void {
|
||||
airport.planning.assignments.forEach((assignment) => {
|
||||
if (
|
||||
assignment.type !== 'SHALL' &&
|
||||
assignment.type !== 'SHOULD' &&
|
||||
assignment.type !== 'MAY'
|
||||
) {
|
||||
throw new HttpException(
|
||||
'Invalid assignment type',
|
||||
HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static validateConstraint(constraint: ConstraintDto): void {
|
||||
if (
|
||||
constraint.altitude.mode !== 'BELOW' &&
|
||||
constraint.altitude.mode !== 'EXACT' &&
|
||||
constraint.altitude.mode !== 'ABOVE'
|
||||
) {
|
||||
throw new HttpException(
|
||||
'Invalid altitude constraint mode',
|
||||
HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
);
|
||||
}
|
||||
if (
|
||||
constraint.speed.mode !== 'BELOW' &&
|
||||
constraint.speed.mode !== 'EXACT' &&
|
||||
constraint.speed.mode !== 'ABOVE'
|
||||
) {
|
||||
throw new HttpException(
|
||||
'Invalid speed constraint mode',
|
||||
HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private static validateAirportConstraints(airport: AirportDto): void {
|
||||
airport.upperConstraints.forEach((constraint) =>
|
||||
AirportController.validateConstraint(constraint),
|
||||
);
|
||||
|
||||
airport.arrivalRoutes.forEach((route) => {
|
||||
route.constraints.forEach((constraint) =>
|
||||
AirportController.validateConstraint(constraint),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@Get('/allCodes')
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
@@ -221,7 +271,18 @@ export class AirportController {
|
||||
status: 409,
|
||||
description: 'The airport is already registered',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 422,
|
||||
description: 'The assignment type is invalid',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 422,
|
||||
description: 'The constraint type is invalid',
|
||||
})
|
||||
async register(@Body('airport') airport: AirportDto): Promise<void> {
|
||||
AirportController.validateAirportConstraints(airport);
|
||||
AirportController.validateAirportEnums(airport);
|
||||
|
||||
await this.airportService
|
||||
.registerAirport(AirportController.airportDtoToAirport(airport))
|
||||
.then((registered) => {
|
||||
|
||||
Reference in New Issue
Block a user