mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-04-08 02:42:08 +01:00
* Fixes issue where empty partition key is treated like nonexistent key for Tables API * Updated format * Refactor fix * Prettier * Fixes issue when CRUD with no parition key for all APIs * Format fix * Refactor to explicitly check for Tables
27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
import { CollectionBase } from "../../Contracts/ViewModels";
|
|
import DocumentId from "../../Explorer/Tree/DocumentId";
|
|
import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
|
|
import { client } from "../CosmosClient";
|
|
import { getEntityName } from "../DocumentUtility";
|
|
import { handleError } from "../ErrorHandlingUtils";
|
|
import { getPartitionKeyValue } from "./getPartitionKeyValue";
|
|
|
|
export const deleteDocument = async (collection: CollectionBase, documentId: DocumentId): Promise<void> => {
|
|
const entityName: string = getEntityName();
|
|
const clearMessage = logConsoleProgress(`Deleting ${entityName} ${documentId.id()}`);
|
|
|
|
try {
|
|
await client()
|
|
.database(collection.databaseId)
|
|
.container(collection.id())
|
|
.item(documentId.id(), getPartitionKeyValue(documentId))
|
|
.delete();
|
|
logConsoleInfo(`Successfully deleted ${entityName} ${documentId.id()}`);
|
|
} catch (error) {
|
|
handleError(error, "DeleteDocument", `Error while deleting ${entityName} ${documentId.id()}`);
|
|
throw error;
|
|
} finally {
|
|
clearMessage();
|
|
}
|
|
};
|