File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { ClassTransformer } from './ClassTransformer' ;
1
2
import { defaultMetadataStorage } from "./storage" ;
2
3
import { TypeMetadata } from "./metadata/TypeMetadata" ;
3
4
import { ExposeMetadata } from "./metadata/ExposeMetadata" ;
@@ -48,4 +49,30 @@ export function Exclude(options?: ExcludeOptions) {
48
49
const metadata = new ExcludeMetadata ( object instanceof Function ? object : object . constructor , propertyName , options || { } ) ;
49
50
defaultMetadataStorage . addExcludeMetadata ( metadata ) ;
50
51
} ;
52
+ }
53
+
54
+ /**
55
+ * Return the object with the exposed properties only.
56
+ */
57
+ export function JsonView ( params : { } , method ?: string ) : Function {
58
+
59
+ return function ( target : any , propertyKey : string , descriptor : PropertyDescriptor ) {
60
+ const classTransformer : any = new ClassTransformer ( ) ;
61
+ const originalMethod = descriptor . value ;
62
+
63
+ descriptor . value = function ( ...args : any [ ] ) {
64
+ let result : any = originalMethod . apply ( this , args ) ;
65
+
66
+ let transformer : Function ;
67
+ if ( typeof method === 'string' && method ) {
68
+ transformer = classTransformer [ method ] ;
69
+ }
70
+ else {
71
+ transformer = classTransformer . classToPlain ;
72
+ }
73
+
74
+ result = transformer ( result , params ) ;
75
+ return result ;
76
+ }
77
+ }
51
78
}
You can’t perform that action at this time.
0 commit comments