import { CosmosContainerClient , cosmosContainerClientTypes } from 'azure-services' ; import { inject , injectable } from 'inversify' ; import { BatchPoolLoadSnapshot , ItemType , PartitionKey } from 'storage-documents' ; @ injectable ( ) export class BatchPoolLoadSnapshotProvider { public constructor ( @ inject ( cosmosContainerClientTypes . OnDemandSystemDataCosmosContainerClient ) private readonly cosmosContainerClient ) { } public async writeBatchPoolLoadSnapshot ( batchPoolLoadSnapshot ) { batchPoolLoadSnapshot . id = this . getDocumentId ( batchPoolLoadSnapshot . batchAccountName , batchPoolLoadSnapshot . poolId ) ; batchPoolLoadSnapshot . itemType = ItemType . batchPoolLoadSnapshot ; batchPoolLoadSnapshot . partitionKey = PartitionKey . batchPoolLoadSnapshots ; await this . cosmosContainerClient . writeDocument ( batchPoolLoadSnapshot ) ; } public async readBatchPoolLoadSnapshot ( batchAccountName , poolId ) { const documentId = this . getDocumentId ( batchAccountName , poolId ) ; const response = await this . cosmosContainerClient . readDocument < BatchPoolLoadSnapshot > ( documentId , PartitionKey . batchPoolLoadSnapshots ) ; return response . item ; } private getDocumentId ( batchAccountName , poolId ) { return `${ batchAccountName }.${ poolId }` ; } }