30718/hyperledger-fabric-how-parse-arrays-req-body-node-js-express
I am getting an array in request body like this:
[
{
"month" : "JUL",
"year" :"2018"
},
{
"month" : "JAN",
"year" :"2018"
},
{
"month" : "MAR",
"year" :"2018"
}
]
This has two parameters (month:enum and year:string).
I want to loop through this array and call the chaincode and then send the response. I have tried this:
for(var i=0; i<req.body.length; i++) {
var month = req.body[i].month;
var year = req.body[i].year;
var monthYear = month + year;
key = monthYear + "_new";
console.log("Key is ", key);
var request = {
//targets: let default to the peer assigned to the client
chaincodeId: 'abc',
fcn: 'getTransactionsByKey',
args: [key]
//Calling chaincode smartcontract
return channel.queryByChaincode(request);
}
But because I am passing two values in input, the 2nd value result overrides the first one. Can someone tell me how to pass both the parameters?
You can get the value from the key:
for (var key in req.body) {
if (req.body.hasOwnProperty(key)) {
let value = req.body[key];
console.log( `value for ${key} is ${value}` )
}
}
You need to map ~/.composer/cards of your Docker host ...READ MORE
Hey, @Harinishree,
With error "Invalid network configuration due ...READ MORE
I know it is a bit late ...READ MORE
The peers communicate among them through the ...READ MORE
Summary: Both should provide similar reliability of ...READ MORE
This will solve your problem
import org.apache.commons.codec.binary.Hex;
Transaction txn ...READ MORE
To read and add data you can ...READ MORE
Hi, the command you are using to ...READ MORE
You can access transaction ID in Invoke ...READ MORE
OR
Already have an account? Sign in.