Skip to content

Commit 1fb950e

Browse files
committed
fix(jsonView): add support for promise
1 parent 06b46e0 commit 1fb950e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/decorators.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,15 @@ export function JsonView(params?: {}, method?: string): Function {
6161
const originalMethod = descriptor.value;
6262

6363
descriptor.value = function(...args: any[]) {
64-
let result: any = originalMethod.apply(this, args);
6564
let transformer: Function = typeof method === "string" && method ? classTransformer[method] : classTransformer.classToPlain;
65+
let result: any = originalMethod.apply(this, args);
66+
67+
if (!!result && (typeof result === 'object' || typeof result === 'function') && typeof result.then === 'function') {
68+
// If result is an instance of Promise.
69+
return result.then((data: any) => {
70+
return transformer(result, params);
71+
});
72+
}
6673

6774
result = transformer(result, params);
6875
return result;

0 commit comments

Comments
 (0)