Open
Description
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