Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

302
Visualizações
How to deal with NestJS @Get() decorator?

This block of code works properly. I'm able to access both functions with the URL http://localhost:3000/vehicle/availableVehicles & http://localhost:3000/vehicle/1 accordingly

    @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);
        }
  }

But when I just swap between the 2 functions like code block below then the function availableVehicles() doesn't work & the URL http://localhost:3000/vehicle/availableVehicles hits the getbyId() function. What to do? Or what I'm doing wrong? Thanks in advance.

    @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();
        }
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You just do exactly what you did in the first example, put the more specific routes above the ones that take route parameters.

When the server's routing table is being built on application startup they will be discovered and registered in this order.

This is a duplicate of https://stackoverflow.com/a/68727403/1364771

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda