File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -51,15 +51,29 @@ export function writeResultToResponse(
5151 // See https://github.com/loopbackio/loopback-next/issues/436
5252 response . setHeader ( 'Content-Type' , 'application/json' ) ;
5353 let customResult = result ;
54- if ( result . length ) {
55- customResult = [ ] ;
56- result . forEach ( ( item : { [ key : string ] : Object [ ] } ) => {
57- const org : { [ key : string ] : Object [ ] } = { } ;
58- Object . keys ( item ) . forEach ( key => {
59- org [ key ] = item [ key ] ;
54+ let org : { [ key : string ] : Object [ ] } = { } ;
55+
56+ if ( result && typeof result === 'object' ) {
57+ if ( Array . isArray ( result ) ) {
58+ customResult = [ ] ;
59+ result . forEach ( ( item : { [ key : string ] : Object [ ] } ) => {
60+ org = { } ;
61+ if ( typeof item === 'object' ) {
62+ Object . keys ( item ) . forEach ( key => {
63+ org [ key ] = item [ key ] ;
64+ } ) ;
65+ customResult . push ( org ) ;
66+ } else {
67+ customResult . push ( item ) ;
68+ }
69+ } ) ;
70+ } else {
71+ org = { } ;
72+ Object . keys ( result ) . forEach ( key => {
73+ org [ key ] = result [ key ] ;
6074 } ) ;
61- customResult . push ( org ) ;
62- } ) ;
75+ customResult = org ;
76+ }
6377 }
6478 // TODO(bajtos) handle errors - JSON.stringify can throw
6579 result = JSON . stringify ( customResult ) ;
You can’t perform that action at this time.
0 commit comments