Skip to content

feat: allow defining different groups for toPlain and toClass operations #378

Open
@NoNameProvided

Description

@NoNameProvided

Description

Note: Requested by @slavafomin, this issue is created from #57.

Users should be able to allow defining different groups for plainToClass and classToPlain. Example:

@Exclude()
class User {
  @Expose({ toClassOnly: true, groups: ["create", "update"] })
  @Expose({ toPlainOnly: true })
  public email?: string;

  @Expose({ toClassOnly: true, groups: ["create", "update"] })
  @Expose({ toPlainOnly: true })
  public firstName?: string;

  @Expose({ toClassOnly: true, groups: ["create"] })
  @Expose({ toPlainOnly: true })
  public password?: string;
}
const instance = plainToClass(User, {
  email: "email@example.com",
  firstName: "John",
  password: "12345"
}, { groups: ["update"] });

/* Instance should be { firstName: 'John', email: 'email@example.com'  }*/
// parameter is a User instance
const json= classToPlain(<User>{
  email: "email@example.com",
  firstName: "John",
  password: "12345"
});

/* JSON should be { firstName: 'John', password: '12345', email: 'email@example.com'  }*/

We need to discuss what is the motivation behind this and can we achieve this with the current toolset or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: featureIssues related to new features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions