In below code:
- http call gets multiple orderline's (items) IDs
- for each of those makes another http call and reserves them. I then need to redo the page with those showing up as reserved.
Whith numerous items, the last 3 lines would execute and reload the page before they actually got reserved in the BE so I added that 0.7 sec delay but that's not best practice and I can't figure out how to do it otherwise (switchMap? how)
this.service.getOrderlineId(this.orderlineIds).subscribe((ids: Number[]) => {
ids.forEach(id => {
this.currentReservation = {
orderline: id,
company: this.currentUser.company_id,
company_name: this.currentCompany.name,
user: this.currentUser.user_id,
delivery_address: this.currentCompany.address
}
this.service.createOrderLineReservation(this.currentReservation).subscribe(reservation => {
})
})
})
setTimeout(() => {
this.clearGroups();
this.prepareRow();
this.prepareGroups();
}, 700);