Skip to content

Commit d067241

Browse files
committed
fix: improve implmenetation for group by
Signed-off-by: Muhammad Aaqil <[email protected]>
1 parent e145a31 commit d067241

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

packages/rest/src/writer.ts

+35-26
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,42 @@ export function writeResultToResponse(
5050
// TODO(ritch) remove this, should be configurable
5151
// See https://github.com/loopbackio/loopback-next/issues/436
5252
response.setHeader('Content-Type', 'application/json');
53-
let customResult = result;
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];
74-
});
75-
customResult = org;
76-
}
77-
}
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+
// }
7880
// TODO(bajtos) handle errors - JSON.stringify can throw
79-
result = JSON.stringify(customResult);
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------------');
8089
}
8190
break;
8291
default:

0 commit comments

Comments
 (0)