Skip to content

Commit ac769e9

Browse files
committed
fix(jsonView): simplify return
1 parent 8ea8072 commit ac769e9

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/decorators.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,11 @@ export function JsonView(params?: {}, method?: string): Function {
6464
let transformer: Function = typeof method === "string" && method ? classTransformer[method] : classTransformer.classToPlain;
6565
let result: any = originalMethod.apply(this, args);
6666

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) => transformer(data, params));
70-
}
67+
let isPromise = !!result && (typeof result === "object" || typeof result === "function") && typeof result.then === "function";
7168

72-
result = transformer(result, params);
73-
return result;
69+
return isPromise ?
70+
result.then((data: any) => transformer(data, params)) :
71+
transformer(result, params);
7472
};
7573
};
7674
}

0 commit comments

Comments
 (0)