I currently have the following code in my app:
import {getTestData,getUserData} from "./js/apiInteractorModule.js";
const TEST_NAMES = ['CM10'];
var testData = {};
function populateTestData(){
return axios({
method: 'post',
url: '/get-session-cookie'
}).then(response => { //Get decrypted session data
getUserData(response.data.uuid,response.data.id_token).then(response => { //Get user data w/ decrypted session data (TODO: Integrate w/ data)
for (let i = 0; i < TEST_NAMES.length; i++){
getTestData(TEST_NAMES[i]).then(response => {
testData[TEST_NAMES[i]] = [];
for (var key in response.json){ //Creates {NAME: [{x: time, y: value}]} TODO: Adjust w/ user data
testData[TEST_NAMES[i]].push({
x: response.json[key].time,
y: response.json[key].value
});
}
});
}
})
return response;
}).catch(error => {
console.log(error);
return error;
});
}
Where getUserData and getTestData interact w/ my external API. The getTestData endpoint returns something like
{success: True/False, json: {String key: {time: UNIX time, value: float}}}
After running this, I would thus expect testData to look like
{CM10: [{x: time, y: value}]} for each value and time received in the API call.
When running
populateTestData().then(response => {
console.log(testData);
});
though, instead of getting the expected dictionary, the console.log prints
console.log(testData[CM10])
also prints undefined, and testData.values are also empty.
Just for contrast, when I initialize testData outside of the function w/
var testData = {"CM10": 10}
And then run the same code, the output is
And running console.log(testData["CM10"])"
prints 10
Why is this, and what can I do to fix it?