Skip to content

feature: transform with group only #1197

Open
@kvernon

Description

@kvernon

Description

When looking at the landscape today, we can include items by transforming and including groups, however, we can only be inclusive with the group identifier. What would be great if we could transform where only output properties that were tagged with a group.

import { Exclude, Expose, classToPlain } from 'class-transformer';

export class User {
  id: number;

  name: string;

  @Expose({ groups: ['user', 'admin'] }) // this means that this data will be exposed only to users and admins
  email: string;

  @Expose({ groups: ['user'] }) // this means that this data will be exposed only to users
  password: string;
}

let user1 = classToPlain(user, { groups: ['user'] }); // will contain id, name, email and password
let user2 = classToPlain(user, { groups: ['admin'] }); // will contain id, name and email

Proposed solution

Possibly allow an optional boolean to say groupsOnly

let user1 = classToPlain(user, { groups: ['user'], { groupsOnly: true }); // will contain email and password
let user2 = classToPlain(user, { groups: ['admin'], { groupsOnly: true });  // will contain  email

Metadata

Metadata

Assignees

No one assigned

    Labels

    flag: needs discussionIssues which needs discussion before implementation.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