Skip to content

Commit

Permalink
Fix automatic field camel casing for subscriber attribs
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Sep 19, 2021
1 parent 4e5e466 commit 1df827c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions frontend/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1df827c

Please sign in to comment.