getAccomodationCost is a function which is expected to return a promise with a return value. Now It's throwing an error resolve is undefined.
This error message is thrown at line resolve(JSON.parse(JSON.stringify(result))) inside promise then. If i replace keyword resolve with return then Promise.all call in the main function will fail.
Can some one help me to return a promise with a return value JSON.parse(JSON.stringify(result)) from the below function.
var getAccomodationCost = function (req, res) {
var accomodationCostPromise = new Promise(function (resolve, reject)
{
getHospitalStayDuration(req, res, function (duration) {
resolve(duration)
})
})
.then(function (duration) {
hotelModel.aggregate([
//Some logic here
], function (err, result) {
resolve(JSON.parse(JSON.stringify(result)))
})
})
return accomodationCostPromise;
}
//Main function where the above snippet is called
const promise1 = somefunction(req, res);
const accomodationCostPromise = getAccomodationCost(req, res)
Promise.all([promise1,accomodationCostPromise])
.then(([hospitalInfo,accomodationCost]) => {
//Return some json response from here
}).catch(function (err) {
return res.json({ "Message": err.message });
});