Fix automatic field camel casing for subscriber attribs

This commit is contained in:
Kailash Nadh 2021-09-19 12:39:00 +05:30
parent 4e5e466b03
commit 1df827c58a

View file

@ -41,19 +41,20 @@ http.interceptors.response.use((resp) => {
}
if (resp.config.preserveCase && resp.config.preserveResultsCase) {
resp.data.data.results.forEach((r, n) => {
// Only preserve case for certain keys under the 'results' key.
const save = {};
resp.config.preserveResultsCase.forEach((key) => {
save[key] = JSON.stringify(r[key]);
});
// For each key in preserveResultsCase, get the values out in an array of arrays
// and save them as stringified JSON.
const save = resp.data.data.results.map(
(r) => resp.config.preserveResultsCase.map((k) => JSON.stringify(r[k])),
);
const item = humps.camelizeKeys(r);
Object.keys(save).forEach((key) => {
item[key] = JSON.parse(save[key]);
});
// Camelcase everything.
data = humps.camelizeKeys(resp.data.data);
data.results[n] = item;
// Put the saved results back.
data.results.forEach((r, n) => {
resp.config.preserveResultsCase.forEach((k, i) => {
data.results[n][k] = JSON.parse(save[n][i]);
});
});
}
} else {