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

156
Visualizações
How to access "groups" using "class-transformer" in nested components

I'm trying to limit access to some properties to only users with that property on their group in a deeply nested interface, and I'm unable to access the "groups" metadata in the nested components.

Here is a code example:

Example of response:

export class ProductResponseInterface {
  // groups work fine here 
  @ValidateNested()
  success: boolean;

  @Type(() => ProductFetchResponseInterface)
  data?: ProductFetchResponseInterface;

  error?: string;

  @Exclude()
  groups?: string[];

  constructor(partial: Partial<ProductResponseInterface>) {
    Object.assign(this, partial);
  }
}


export class ProductFetchResponseInterface {
  // groups seem to be undefined here 
  @ValidateNested()
  @Type(() => ProductInterface)
  @Expose({ groups: ['eshop.products'] })
  products: ProductInterface[];
  @Exclude()
  groups: string[];
  count: number;

  constructor(partial: Partial<ProductFetchResponseInterface>) {
    Object.assign(this, partial);
  }
}

export class ProductInterface {
  // groups seems to be undefined here 
  @Expose({ groups: ['eshop.products.product.id', 'admin'] })
  id: number;
  @Expose({ groups: ['eshop.products.product.name'] })
  name: string;
  ...

  constructor(partial: Partial<ProductInterface>) {
    Object.assign(this, partial);
  }
}

The problem: ProductFetchResponseInterface and ProductInterface don't have access to the "groups" tag, and their response returns empty products.

This is the call that uses those interfaces

    const http_response = await this.handle_request(url);
    // { success: true, data: { products: [ { id: 1, name: 'product_name' }]}}
    return plainToInstance(
      ProductResponseInterface,
      {
        ...response,
        groups: user.access_permissions_populated // ['eshop.products', 'eshop.products.product.id',...],
      },
      {},
    );

Any idea on how to make it work? Thanks.

about 4 years ago · Santiago Trujillo
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