@@ -50,42 +50,32 @@ export function writeResultToResponse(
50
50
// TODO(ritch) remove this, should be configurable
51
51
// See https://github.com/loopbackio/loopback-next/issues/436
52
52
response . setHeader ( 'Content-Type' , 'application/json' ) ;
53
- // let customResult = result;
54
- // let org: {[key: string]: Object[]} = {};
55
- // if (result && typeof result === 'object') {
56
- // if (Array.isArray(result)) {
57
- // customResult = [];
58
- // result.forEach((item: {[key: string]: Object[]}) => {
59
- // org = {};
60
- // if (typeof item === 'object') {
61
- // Object.keys(item).forEach(key => {
62
- // org[key] = item[key];
63
- // });
64
- // customResult.push(org);
65
- // } else {
66
- // customResult.push(item);
67
- // }
68
- // });
69
- // } else {
70
- // org = {};
71
- // Object.keys(result).forEach(key => {
72
- // console.log('-----------------');
73
- // console.log(key);
74
- // console.log('-----------------');
75
- // org[key] = result[key];
76
- // });
77
- // customResult = org;
78
- // }
79
- // }
53
+ let customResult = result ;
54
+ let org : { [ key : string ] : Object [ ] } = { } ;
55
+ if ( result && typeof result === 'object' ) {
56
+ if ( Array . isArray ( result ) ) {
57
+ customResult = [ ] ;
58
+ result . forEach ( ( item : { [ key : string ] : Object [ ] } ) => {
59
+ org = { } ;
60
+ if ( typeof item === 'object' ) {
61
+ Object . keys ( item ) . forEach ( key => {
62
+ org [ key ] = item [ key ] ;
63
+ } ) ;
64
+ customResult . push ( org ) ;
65
+ } else {
66
+ customResult . push ( item ) ;
67
+ }
68
+ } ) ;
69
+ } else {
70
+ org = { } ;
71
+ Object . keys ( result ) . forEach ( key => {
72
+ org [ key ] = result [ key ] ;
73
+ } ) ;
74
+ customResult = org ;
75
+ }
76
+ }
80
77
// TODO(bajtos) handle errors - JSON.stringify can throw
81
- // result = JSON.stringify(customResult);
82
- console . log ( '------------before------------' ) ;
83
- console . log ( result ) ;
84
- console . log ( '------------before------------' ) ;
85
- result = JSON . stringify ( result ) ;
86
- console . log ( '------------after------------' ) ;
87
- console . log ( result ) ;
88
- console . log ( '------------after------------' ) ;
78
+ result = JSON . stringify ( customResult ) ;
89
79
}
90
80
break ;
91
81
default :
0 commit comments