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

173
Views
Cómo acceder a "grupos" usando "class-transformer" en componentes anidados

Estoy tratando de limitar el acceso a algunas propiedades solo a los usuarios con esa propiedad en su grupo en una interfaz profundamente anidada, y no puedo acceder a los metadatos de "grupos" en los componentes anidados.

Aquí hay un ejemplo de código:

Ejemplo de respuesta:

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

El problema: ProductFetchResponseInterface y ProductInterface no tienen acceso a la etiqueta de "grupos" y su respuesta devuelve productos vacíos.

Esta es la llamada que usa esas 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',...], }, {}, );

¿Alguna idea sobre cómo hacer que funcione? Gracias.

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!