Skip to content

Commit e3f8f2f

Browse files
committed
fix(jsonView): added documenation and code-review fixes
1 parent 5d6219b commit e3f8f2f

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
build/
22
node_modules/
33
coverage/
4-
npm-debug.log
4+
npm-debug.log
5+
.idea
6+
.vscode

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -593,15 +593,15 @@ it will convert a date value in your photo object to moment date.
593593
## Other decorators
594594
| Signature | Example | Description
595595
|--------------------|------------------------------------------|---------------------------------------------|
596-
| `@TransformMethod` | `@TransformMethod({ groups: ["user"] })` | Transform the method return with classToPlain and expose the properties on the class.
596+
| `@TransformClassToPlain` | `@TransformClassToPlain({ groups: ["user"] })` | Transform the method return with classToPlain and expose the properties on the class.
597+
| `@TransformClassToClass` | `@TransformClassToClass({ groups: ["user"] })` | Transform the method return with classToClass and expose the properties on the class.
597598

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
599+
The above decorators accept one optional argument:
600+
ClassTransformOptions - The transform options like groups, version, name
601601

602602
An example:
603603

604-
```
604+
```typescript
605605
@Exclude()
606606
class User {
607607

@@ -621,7 +621,7 @@ class User {
621621

622622
class UserController {
623623

624-
@TransformMethod({ groups: ['user.email'] })
624+
@TransformClassToPlain({ groups: ['user.email'] })
625625
getUser() {
626626
const user = new User();
627627
user.firstName = "Snir";

src/decorators.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,13 @@ export function TransformClassToPlain(params?: ClassTransformOptions): Function
5959

6060
return function (target: Function, propertyKey: string, descriptor: PropertyDescriptor) {
6161
const classTransformer: ClassTransformer = new ClassTransformer();
62-
const MethodTransformer: Function = classTransformer.classToPlain;
6362
const originalMethod = descriptor.value;
6463

6564
descriptor.value = function(...args: any[]) {
6665
const result: any = originalMethod.apply(this, args);
6766
const isPromise = !!result && (typeof result === "object" || typeof result === "function") && typeof result.then === "function";
6867

69-
return isPromise ? result.then((data: any) => MethodTransformer(data, params)) : MethodTransformer(result, params);
68+
return isPromise ? result.then((data: any) => classTransformer.classToPlain(data, params)) : classTransformer.classToPlain(result, params);
7069
};
7170
};
7271
}
@@ -78,14 +77,13 @@ export function TransformClassToClass(params?: ClassTransformOptions): Function
7877

7978
return function (target: Function, propertyKey: string, descriptor: PropertyDescriptor) {
8079
const classTransformer: ClassTransformer = new ClassTransformer();
81-
const MethodTransformer: Function = classTransformer.classToClass;
8280
const originalMethod = descriptor.value;
8381

8482
descriptor.value = function(...args: any[]) {
8583
const result: any = originalMethod.apply(this, args);
8684
const isPromise = !!result && (typeof result === "object" || typeof result === "function") && typeof result.then === "function";
8785

88-
return isPromise ? result.then((data: any) => MethodTransformer(data, params)) : MethodTransformer(result, params);
86+
return isPromise ? result.then((data: any) => classTransformer.classToClass(data, params)) : classTransformer.classToClass(result, params);
8987
};
9088
};
9189
}

0 commit comments

Comments
 (0)