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.