Skip to content

Commit

Permalink
Fixed api scope subscriptions in profile (#978)
Browse files Browse the repository at this point in the history
  • Loading branch information
ygrik authored Oct 19, 2020
1 parent f2875bb commit 92b29b0
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/services/productService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as Constants from "../constants";
import { Utils } from "../utils";
import { SearchQuery } from "../contracts/searchQuery";
import { SubscriptionSecrets } from "../contracts/subscriptionSecrets";
import { ApiContract } from "../contracts/api";

/**
* A service for management operations with products.
Expand Down Expand Up @@ -118,19 +119,31 @@ export class ProductService {

for (const subscription of subscriptions) {
const subscriptionModel = new Subscription(subscription);

if (subscription.properties.scope.endsWith("/apis")) {
subscriptionModel.productName = "All APIs";
} else {
const productName = Utils.getResourceName("products", subscription.properties.scope);

const productPromise = this.mapiClient
.get<ProductContract>(`/products/${productName}`)
.then(product => {
subscriptionModel.productName = product.properties.displayName;
});

promises.push(productPromise);
}
} else
if (subscription.properties.scope.includes("/apis/")) {
const apiName = Utils.getResourceName("apis", subscription.properties.scope);

const apiPromise = this.mapiClient
.get<ApiContract>(`/apis/${apiName}`)
.then(api => {
subscriptionModel.productName = `API: ${api.properties.displayName}`;
});

promises.push(apiPromise);
} else {
const productName = Utils.getResourceName("products", subscription.properties.scope);

const productPromise = this.mapiClient
.get<ProductContract>(`/products/${productName}`)
.then(product => {
subscriptionModel.productName = product.properties.displayName;
});

promises.push(productPromise);
}

const secretPromise = this.mapiClient
.post<SubscriptionSecrets>(`${userId}/subscriptions/${subscription.name}/listSecrets`)
Expand Down

0 comments on commit 92b29b0

Please sign in to comment.