Skip to content

Commit c1a0264

Browse files
committed
fix(readme): update readme
1 parent 524a192 commit c1a0264

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,55 @@ Now when you call `plainToClass` and send a plain representation of the Photo ob
590590
it will convert a date value in your photo object to moment date.
591591
`@Transform` decorator also supports groups and versioning.
592592

593+
## Other decorators
594+
| Signature | Example | Description
595+
|--------------------|------------------------------------------|---------------------------------------------|
596+
| `@TransformMethod` | `@TransformMethod({ groups: ["user"] })` | Transform the method return with classToPlain and expose the properties on the class.
597+
598+
The `@TransformMethod` decorator accept 2 optional arguments.
599+
1. ClassTransformOptions - The transform options like groups, version, name
600+
2. the method to do the transform - classToPlain or classToClass
601+
602+
An example:
603+
604+
```
605+
@Exclude()
606+
class User {
607+
608+
id: number;
609+
610+
@Expose()
611+
firstName: string;
612+
613+
@Expose()
614+
lastName: string;
615+
616+
@Expose({ groups: ['user.email'] })
617+
email: string;
618+
619+
password: string;
620+
}
621+
622+
class UserController {
623+
624+
@TransformMethod({ groups: ['user.email'] })
625+
getUser() {
626+
const user = new User();
627+
user.firstName = "Snir";
628+
user.lastName = "Segal";
629+
user.password = "imnosuperman";
630+
631+
return user;
632+
}
633+
}
634+
635+
const controller = new UserController();
636+
const user = controller.getUser();
637+
```
638+
639+
the `user` variable will contain only firstName,lastName, email properties becuase they are
640+
the exposed variables. email property is also exposed becuase we metioned the group "user.email".
641+
593642
## Working with generics
594643

595644
Generics are not supported because TypeScript does not have good reflection abilities yet.

0 commit comments

Comments
 (0)