class-transformer icon indicating copy to clipboard operation
class-transformer copied to clipboard

question: Exclude property of type

Open AmedeoD96 opened this issue 3 years ago • 2 comments

Is it possible to exlude a property of nested object? For example:

export class Foo {
  public prop1: string;
  public prop2: string;
  public prop3: string; // <== Property to exclude
}

export class Bar {
  @Type(() => Foo)
  public prop: Foo[];
}

I can't use @Exclude() decorator because I need to exclude the property only in the Bar class and not in the other classes that extends Foo.

AmedeoD96 avatar Dec 01 '21 11:12 AmedeoD96

read docs about expose groups

ruscon avatar Dec 12 '21 09:12 ruscon

@AmedeoD96 is it working for you?

export class User { @OneToOne(() => Profile, (profile) => profile.user) @JoinColumn() @Expose({ groups: [GROUP_ME] }) profile: Profile; } export class Profile { @PrimaryGeneratedColumn('uuid') @Expose({ groups: [GROUP_ME] }) id: string; }

Response is

"profile": {},

If I remove the @expose from the profile returns the id

tspent avatar Jan 30 '22 18:01 tspent