Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!