refactor: vault files

This commit is contained in:
Mo
2023-05-28 14:11:31 -05:00
parent 690f18708a
commit 94deab2ee0
69 changed files with 761 additions and 212 deletions
@@ -0,0 +1,33 @@
import { DomainEventHandlerInterface, VaultFileUploadedEvent } from '@standardnotes/domain-events'
import { inject, injectable } from 'inversify'
import { Logger } from 'winston'
import TYPES from '../../Bootstrap/Types'
import { VaultServiceInterface } from '../Vault/Service/VaultServiceInterface'
import { VaultsRepositoryInterface } from '../Vault/Repository/VaultRepositoryInterface'
@injectable()
export class VaultFileUploadedEventHandler implements DomainEventHandlerInterface {
constructor(
@inject(TYPES.VaultService) private vaultService: VaultServiceInterface,
@inject(TYPES.VaultRepository) private vaultRepository: VaultsRepositoryInterface,
@inject(TYPES.Logger) private logger: Logger,
) {}
async handle(event: VaultFileUploadedEvent): Promise<void> {
const vault = await this.vaultService.getVault({
vaultUuid: event.payload.vaultUuid,
})
if (vault === null) {
this.logger.warn(`Could not find vault with uuid: ${event.payload.vaultUuid}`)
return
}
vault.fileUploadBytesUsed += event.payload.fileByteSize
await this.vaultRepository.save(vault)
}
}