I'm always stuck when it come to acronyms methods, because of that I'm expriencing some issues with my code. Hope you guys can help me.
So basically, I have 2 funtions on the onInit; however, when "fetchSalesbyDay2" runs, the this.firstResponse is reciving undefined and not saving the first reponse from "fetchSalesbyDay1 "
ngOnInit(): void {
this.fetchSalesbyDay1();
this.fetchSalesbyDay2();
}
fetchSalesbyDay1 = async () => {
const params = {
'reportName': 'home_report',
'query': {
'metric': 'salesByDay',
'showBy': this.period.toString(),
'startDate': parseInt(moment(this.range1sDate, 'MM-DD-YYYY HH:mm').format('X'), 10),
'endDate': parseInt(moment(this.range1eDate, 'MM-DD-YYYY HH:mm').format('X'), 10)
}
};
await this.http
.post(this.GLOBALURL + '/reports/query', params, this.httpOptions1)
.subscribe((response: any) => {
this.firstResponse = response;
});
}
fetchSalesbyDay2 = async () => {
const params = {
'reportName': 'home_report',
'query': {
'metric': 'salesByDay',
'showBy': this.period.toString(),
'startDate': parseInt(moment(this.range2sDate, 'MM-DD-YYYY HH:mm').format('X'), 10),
'endDate': parseInt(moment(this.range2eDate, 'MM-DD-YYYY HH:mm').format('X'), 10)
}
};
await this.http
.post(this.GLOBALURL + '/reports/query', params, this.httpOptions1)
.subscribe((response: any) => {
this.secondResponse = response;
this.displayandprocessWeekData(this.firstResponse, this.secondResponse);
});
}
I would like that, once "fetchSalesbyDay1" finishes, and this.firstResponse has already a value, the "fetchSalesbyDay2" can execute. What would be the best way to solve this ?