I am pushing the promises in promises =[] array but when passing the promises in promises. All the array remains null which resolves and send null result if my code has any issue please answer
searchProductVariant: (start, end, combinations) => {
return new Promise((resolve,reject)=>
{
var promises = [];
console.log(start, " ", end);
for (let i = start; i < start + end; i++) {
vv = combinations[i - start].product_variant_name.split("_");
console.log("kk", vv);
vv.forEach((v) => {
sql = `SELECT id FROM ecommerce.variant_values as varval where varval.value like '${v}'`;
pool.query(sql, [], (error, results, fields) => {
if (error) {
console.log("the errrror is", error);
}
if (results[0].id) {
console.log("i is ", i);
let temp = addProductVariantDetails(i, results[0].id);
promises.push(temp
);
}
});
});
}
console.log(promises); //it prints null
return Promise.all(promises)
.then((resul) => {
return resolve(resul);
})
.catch((err) => {
return reject(err);
});
})
}