cosmos-explorer/src/Common/dataAccess/readOfferWithSDK.ts
Craig Boger (from Dev Box) 56f50e1320 Updated to have a write client and multiple read clients. Added enum to help with selection of client based on needed operation.
Need to modify endpoint selection in CosmosClient to select endpoints based on client called.
2024-03-28 15:35:13 -07:00

28 lines
877 B
TypeScript

import { RequestOptions } from "@azure/cosmos";
import { Offer } from "../../Contracts/DataModels";
import { HttpHeaders } from "../Constants";
import { ClientOperationType, client } from "../CosmosClient";
import { parseSDKOfferResponse } from "../OfferUtility";
import { readOffers } from "./readOffers";
export const readOfferWithSDK = async (offerId: string, resourceId: string): Promise<Offer> => {
if (!offerId) {
const offers = await readOffers();
const offer = offers.find((offer) => offer.resource === resourceId);
if (!offer) {
return undefined;
}
offerId = offer.id;
}
const options: RequestOptions = {
initialHeaders: {
[HttpHeaders.populateCollectionThroughputInfo]: true,
},
};
const response = await client(ClientOperationType.READ).offer(offerId).read(options);
return parseSDKOfferResponse(response);
};