2020-11-19 17:13:11 -08:00
|
|
|
import { Offer, SDKOfferDefinition } from "../Contracts/DataModels";
|
|
|
|
import { OfferResponse } from "@azure/cosmos";
|
2020-12-11 13:38:57 -06:00
|
|
|
import { HttpHeaders } from "./Constants";
|
2020-11-19 17:13:11 -08:00
|
|
|
|
2021-01-08 20:14:12 -06:00
|
|
|
export const parseSDKOfferResponse = (offerResponse: OfferResponse): Offer | undefined => {
|
|
|
|
const offerDefinition: SDKOfferDefinition | undefined = offerResponse?.resource;
|
|
|
|
if (!offerDefinition) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2020-11-19 17:13:11 -08:00
|
|
|
const offerContent = offerDefinition.content;
|
|
|
|
if (!offerContent) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const minimumThroughput = offerContent.collectionThroughputInfo?.minimumRUForCollection;
|
|
|
|
const autopilotSettings = offerContent.offerAutopilotSettings;
|
|
|
|
|
2021-01-08 20:14:12 -06:00
|
|
|
if (autopilotSettings && autopilotSettings.maxThroughput && minimumThroughput) {
|
2020-11-19 17:13:11 -08:00
|
|
|
return {
|
|
|
|
id: offerDefinition.id,
|
|
|
|
autoscaleMaxThroughput: autopilotSettings.maxThroughput,
|
|
|
|
manualThroughput: undefined,
|
|
|
|
minimumThroughput,
|
|
|
|
offerDefinition,
|
2021-01-20 09:15:01 -06:00
|
|
|
offerReplacePending: offerResponse.headers?.[HttpHeaders.offerReplacePending] === "true",
|
2020-11-19 17:13:11 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
id: offerDefinition.id,
|
|
|
|
autoscaleMaxThroughput: undefined,
|
|
|
|
manualThroughput: offerContent.offerThroughput,
|
|
|
|
minimumThroughput,
|
|
|
|
offerDefinition,
|
2021-01-20 09:15:01 -06:00
|
|
|
offerReplacePending: offerResponse.headers?.[HttpHeaders.offerReplacePending] === "true",
|
2020-11-19 17:13:11 -08:00
|
|
|
};
|
|
|
|
};
|