I have an API when triggered it sent 2 HTTP Get Requests
I want to get the response from the 1st Get Request and store it in a variable
so I can send it with the response of the 2nd Get Request. What is the best way to achieve it
Here is what I tried to do
dummy.get("/api/dummy/memberProfileStats", isAuthenticated, (req, res) => {
const userId = res.locals.user
const memberProfileStatsURL = `/api/reports/users/${userId}/general`
const memberLastLoginURL = `/api/users/${userId}/lastlogin`
getRequest(memberLastLoginURL)
.then(response => {
let lastLoginTime = response.data.result
})
.catch(errorMessage => {
console.log( 'Member Last Login API ERROR: ' + errorMessage)
res.json(errorMessage)
});
getRequest(memberProfileStatsURL)
.then(response => {
let stats = response.data.result
let pointsRank = [150, 500, 1000, 2000, 3500, 5000, 5500]
let totalPoints = stats.totalPoints
res.json({
data: {
totalPoints: stats.totalPoints,
totalPointsRedeemed: stats.totalPointsRedeemed,
availablePoints: (stats.totalPoints - stats.totalPointsRedeemed),
totalSessionTime: secondsToHm(stats.totalSessionTime), //convert sessionTime seconds to hours
loginsCount: stats.totalSessions,
rank: rank(totalPoints, pointsRank),
createdTime: stats.created,
lastLoginTime: lastLoginTime,
},
result: response.data.httpStatusCode
})
})
.catch(errorMessage => {
res.json(errorMessage)
});
})
But i get lastLoginTime is not defined