When trying to consolidate responses from two API calls in the code below, I'm facing an issue where Promise.all is not being invoked. Any suggestions on what might be implemented incorrectly and the best practice to achieve this using Promise.all?
The code snippet below follows the tsoa format and is written in TypeScript.
main.ts
@Post("getStoreDetails")
public async getStoreDetail(@Body() request: express.Request): Promise < any > {
const stackurl = "http://staclurl"
const storeurl = "http://storeurl"
let stack;
let store;
if (request.body.lob === "Stack") {
stack = await axios.post(stackurl, req.body).then(
function(res) {
if (res.data.Header.StatusCode !== '0000') {
throw res.data.Header;
}
const Stackresponse = res.data.Details;
return Stackresponse;
});
}
if (request.body.lob === "Admin") {
store = await axios.post(storeurl, req.body).then(
function(res) {
if (res.data.Header.StatusCode !== '0000') {
throw res.data.Header;
}
const StoreResponse = res.data.Details;
return StoreResponse;
});
}
return Promise.all([stack, store]);
}