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

110
Visualizações
Nest.js Multiple Query Parameters with Same Name

Controller

@Get(')
test(
    @Param('accountId') accountId: string,
    @Query('propertyName') propertyNames: string[],
) {
    console.log(propertyNames);
}

Sample Request localhost:8000?propertyName=test2&propertyName=test3

Output:

[ 'test2', 'test3' ]

This works fine when I have multiple values, but when only one parameter is sent, it creates a string instead of an Array

Request: localhost:8000?propertyName=test3 Generates the output: test3 instead of [test3]

My current approach is to use (as per https://stackoverflow.com/a/4775737/5236575)

propertyName = [].concat(propertyName)

to ensure the value is an array.

Is there a way to force Nest.js to parse the query parameters as a string array at all times as this is required in multiple places across controllers.


Note: ValdiationPipe: transform is set to true

app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Off the top of my head, you could use @Transform decorator from class-transformer to achieve that. You could move the logic of transforming a single string parameter to array with help of that decorator.

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