I am new in node js and having the problem using await function. For each should wait for the next iteration until await executes in the node. In the below code, I always get the consumptionSummaryID as 0 but I want the database insert id for next iteration for case REF.
var consumptionSummaryID=0;
transaction.otherSegments.forEach(async function(segment){
switch (segment.segment) {
case 'PTD': let ptdInsertRaw= await con.query('INSERT INTO `consumption-summary` SET ?', ptdInsert);
consumptionSummaryID= ptdInsertRaw.insertId;
case 'REF':
if(consumptionSummaryID!=0){
// having code related to consumptionSummaryID;
}
}
});
Please help.
Thanks in advance