fix(syncing-server): update storage quota used in a shared vault (#691)

This commit is contained in:
Karol Sójko
2023-08-09 10:05:48 +02:00
committed by GitHub
parent 408fd5a0c6
commit 3415cae093
7 changed files with 176 additions and 0 deletions
@@ -0,0 +1,22 @@
import { DomainEventHandlerInterface, SharedVaultFileRemovedEvent } from '@standardnotes/domain-events'
import { Logger } from 'winston'
import { UpdateStorageQuotaUsedInSharedVault } from '../UseCase/SharedVaults/UpdateStorageQuotaUsedInSharedVault/UpdateStorageQuotaUsedInSharedVault'
export class SharedVaultFileRemovedEventHandler implements DomainEventHandlerInterface {
constructor(
private updateStorageQuotaUsedInSharedVaultUseCase: UpdateStorageQuotaUsedInSharedVault,
private logger: Logger,
) {}
async handle(event: SharedVaultFileRemovedEvent): Promise<void> {
const result = await this.updateStorageQuotaUsedInSharedVaultUseCase.execute({
sharedVaultUuid: event.payload.sharedVaultUuid,
bytesUsed: -event.payload.fileByteSize,
})
if (result.isFailed()) {
this.logger.error(`Failed to update storage quota used in shared vault: ${result.getError()}`)
}
}
}