mirror of
https://github.com/standardnotes/server
synced 2026-07-14 09:01:33 -04:00
refactor: vault files
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user