2020-09-18 16:00:21 -07:00
|
|
|
import { Offer } from "../../Contracts/DataModels";
|
2020-10-26 17:17:41 -05:00
|
|
|
import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
|
2020-09-18 16:00:21 -07:00
|
|
|
import { client } from "../CosmosClient";
|
2020-10-21 14:28:30 -07:00
|
|
|
import { handleError } from "../ErrorHandlingUtils";
|
2020-09-18 16:00:21 -07:00
|
|
|
|
2020-09-24 14:03:37 -07:00
|
|
|
export const readOffers = async (): Promise<Offer[]> => {
|
2020-09-28 12:54:28 -07:00
|
|
|
const clearMessage = logConsoleProgress(`Querying offers`);
|
2020-09-18 16:00:21 -07:00
|
|
|
|
2020-09-28 12:54:28 -07:00
|
|
|
try {
|
|
|
|
const response = await client()
|
|
|
|
.offers.readAll()
|
|
|
|
.fetchAll();
|
|
|
|
return response?.resources;
|
|
|
|
} catch (error) {
|
|
|
|
// This should be removed when we can correctly identify if an account is serverless when connected using connection string too.
|
|
|
|
if (error.message.includes("Reading or replacing offers is not supported for serverless accounts")) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2020-10-21 14:28:30 -07:00
|
|
|
handleError(error, `Error while querying offers`, "ReadOffers");
|
2020-09-28 12:54:28 -07:00
|
|
|
throw error;
|
|
|
|
} finally {
|
|
|
|
clearMessage();
|
|
|
|
}
|
2020-09-18 16:00:21 -07:00
|
|
|
};
|