I have a situation where I need to make multiple service calls simultaneously, but there is one call that must be completed before the others are triggered. I have set it up so that the other calls should only happen after the .then(function() {})
block of the initial call. However, upon checking Chrome Dev Tools and observing an SQL error, it seems like all the calls in the subsequent then clause are firing off earlier than expected. What could be causing this issue?
var promises = [];
if (this.partner.customerId > 0) {
if (this.isDirty('ipn.individualPartnerName')) {
promises.push(this.partnerEditService.updateIndividualName(<Interfaces.IIndividualPartner>this.partner));
}
if (this.isDirty('bpa.mailingAddressForm') || this.isDirty('bpa.streetAddressForm')) {
promises.push(this.partnerEditService.updateAddresses(this.partner));
}
if (this.isDirty('bn.businessName')) {
promises.push(this.partnerEditService.updateBusinessName(<Interfaces.IBusinessPartner>this.partner));
}
if (this.isDirty('rc.individualPartnerResponsibilities') || this.isDirty('rc.businessPartnerResponsibilities')) {
promises.push(this.partnerEditService.updateResponsibilities(this.operation, this.partner));
}
}
this.partnerAddRepository.addExisting(this.operation.operationId, this.partner.customerId)
.then(() => {
this.executeSaves(promises);
});
executeSaves = (promises) => {
this.$q.all(promises)
.finally(() => {
this.$mdDialog.hide(this.partner);
});
}
Here is the partnerAddRepo.addExisting function:
addExisting = (operationId: number, partnerId: number) => {
return this.$http.put(`my/path/to/operation/${operationId}/partner/${partnerId}`);
};
It seems that the service calls within the executeSaves
, which include the 4 different calls, are being executed before the partnerAddRepository.addExisting
call is made. Why might this be happening?