Reputation: 1565
My view-model gives a call to a service A and that service A needs to call another service B. the B will return some value that is required by service A. But this seems not working.
Here is my code.
class BillingService {
rest: BaseRest;
baseUrl: string;
configurationService: ConfigurationService;
constructor() {
this.configurationService = new ConfigurationService();
this.rest = new BaseRest({ basePath: this.baseUrl, isExternal: true });
}
getClaimsSummary() {
this.configurationService.getBillingConfiguration().then((data: BillingConfigurationModel) => {
this.baseUrl = data.billingBaseUrl;
return this.rest.GET<ClaimSummaryModel>("claims/GetClaimsHistory", {});
});
}}
getClaimsSummary is being called by view model
this.billingService.getClaimsSummary().then((data: ClaimSummaryModel) => {
//push to array
});
getClaimsSummary depends on a value (baseUrl) that is returned by configurationService.getBillingConfiguration() . i am trying to understand how to return getClaimsSummary so that is it acceptable by viewmodel as a promise.
Please note that rest is using "bluebird" promise library.
Upvotes: 1
Views: 43
Reputation: 664385
then()
already yields that promise. All you have to do is return
it from your method:
getClaimsSummary() {
return this.configurationService.getBillingConfiguration().then((data: BillingConfigurationModel) => {
// ^^^^^^
this.baseUrl = data.billingBaseUrl;
return this.rest.GET<ClaimSummaryModel>("claims/GetClaimsHistory", {});
});
}
Upvotes: 2