I'm writing a node program that does the below.
- Scan the DynamoDB and get the result.
- Based on the result do the below.
- if the returned value is of size 1. console.log the value.
- If the result is more than 1 concat the result and the print it to the console. Currently I'm able to do get the result and print it in console. if it is greater than one, I'm confused on how can I do this.
Below is my code.
function getMyDueResponses(response, session) {
var responseText='';
console.log('Here is your resuilt' + session.attributes.userData.Count);
console.log(session.attributes.userData.length);
if (session.attributes.userData.Count < 2) {
var res = session.attributes.userData;
var userDueDate = JSON.stringify(res.Items[0].dueDate);
var userDueAmount = JSON.stringify(res.Items[0].dueAmount);
var userTotalBalance = JSON.stringify(res.Items[0].totalBalance);
responseText = `Your next Chubb bill is due on ${userDueDate}. The payment due is ${userDueAmount}$. The full account balance is ${userTotalBalance}$.`;
console.log(responseText);
}
else {
//Here I'm stuck on how to proceed.
}
}
for example. the DB returned the below data.
{
"Items": [
{
"accountId": "12345",
"pin": "1234",
"userId": "user1",
"dueDate": "5/20/2017",
"_id": "2",
"dueAmount": "4000",
"totalBalance": "10000"
}
],
"Count": 1,
"ScannedCount": 4
}
the response should be. I'm able to get this result.
Your bill is due on 5/20/2017. The payment due is 4000$. The full account balance is 10000$.
the db returned the below data.
{
"Items": [
{
"accountId": "12345",
"pin": "1234",
"userId": "user1",
"dueDate": "5/20/2017",
"_id": "2",
"dueAmount": "4000",
"totalBalance": "10000"
},
{
"accountId": "12345",
"pin": "1234",
"userId": "user1",
"dueDate": "5/23/2017",
"_id": "2",
"dueAmount": "1000",
"totalBalance": "10000"
},
{
"accountId": "12345",
"pin": "1234",
"userId": "user1",
"dueDate": "5/24/2017",
"_id": "2",
"dueAmount": "300",
"totalBalance": "10000"
}
],
"Count": 3,
"ScannedCount": 4
}
the below data has to be printed in console.log()
.
Your bill 1 is due on 5/20/2017. The payment due is 4000$. The full account balance is 10000$. Your bill 2 is due on 5/23/2017. The payment due is 1000$. The full account balance is 10000$. Your bill 3 is due on 5/24/2017. The payment due is 300$. The full account balance is 10000$.
please let me know how can I do this.
via user3872094
No comments:
Post a Comment