Este bloque de código funciona correctamente. Puedo acceder a ambas funciones con la URL http://localhost:3000/vehicle/availableVehicles & http://localhost:3000/vehicle/1 en consecuencia
@Controller('vehicle') export class VehicleController { constructor( private readonly vehicleService: VehicleService, private readonly crudService: CurdService ) { } tableName: string = 'vehicle'; @Get('availableVehicles') async availableVehicles() { return await this.vehicleService.availableVehicles(); } @Get(':id') async getbyId(@Req() request: Request) { return await this.crudService.getById(this.tableName, request.params.id); } } Pero cuando solo cambio entre las 2 funciones como el bloque de código a continuación, la función availableVehicles() no funciona y la URL http://localhost:3000/vehicle/availableVehicles activa la función getbyId() . ¿Qué hacer? ¿O qué estoy haciendo mal? Gracias por adelantado.
@Controller('vehicle') export class VehicleController { constructor( private readonly vehicleService: VehicleService, private readonly crudService: CurdService ) { } tableName: string = 'vehicle'; @Get(':id') async getbyId(@Req() request: Request) { return await this.crudService.getById(this.tableName, request.params.id); } @Get('availableVehicles') async availableVehicles() { return await this.vehicleService.availableVehicles(); } }Simplemente haga exactamente lo que hizo en el primer ejemplo, coloque las rutas más específicas sobre las que toman parámetros de ruta.
Cuando se crea la tabla de enrutamiento del servidor al iniciar la aplicación, se detectarán y registrarán en este orden.
Este es un duplicado de https://stackoverflow.com/a/68727403/1364771