mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-04-13 21:32:26 +01:00
26 lines
1.0 KiB
TypeScript
26 lines
1.0 KiB
TypeScript
import { CollectionBase } from "../../Contracts/ViewModels";
|
|
import { client } from "../CosmosClient";
|
|
import { getEntityName } from "../DocumentUtility";
|
|
import { handleError } from "../ErrorHandlingUtils";
|
|
import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
|
|
|
|
export const createDocument = async (collection: CollectionBase, newDocument: unknown): Promise<unknown> => {
|
|
const entityName = getEntityName();
|
|
const clearMessage = logConsoleProgress(`Creating new ${entityName} for container ${collection.id()}`);
|
|
|
|
try {
|
|
const response = await client()
|
|
.database(collection.databaseId)
|
|
.container(collection.id())
|
|
.items.create(newDocument);
|
|
|
|
logConsoleInfo(`Successfully created new ${entityName} for container ${collection.id()}`);
|
|
return response?.resource;
|
|
} catch (error) {
|
|
handleError(error, "CreateDocument", `Error while creating new ${entityName} for container ${collection.id()}`);
|
|
throw error;
|
|
} finally {
|
|
clearMessage();
|
|
}
|
|
};
|