mirror of
https://github.com/standardnotes/server
synced 2026-07-14 00:01:54 -04:00
* fix(auth): safe guard file upload bytes used to be positive intiger * feat: add procedure for recalculating file quota for user * add more meta to logs
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { DomainEventHandlerInterface, FileQuotaRecalculatedEvent } from '@standardnotes/domain-events'
|
|
import { UpdateStorageQuotaUsedForUser } from '../UseCase/UpdateStorageQuotaUsedForUser/UpdateStorageQuotaUsedForUser'
|
|
import { Logger } from 'winston'
|
|
|
|
export class FileQuotaRecalculatedEventHandler implements DomainEventHandlerInterface {
|
|
constructor(
|
|
private updateStorageQuota: UpdateStorageQuotaUsedForUser,
|
|
private logger: Logger,
|
|
) {}
|
|
|
|
async handle(event: FileQuotaRecalculatedEvent): Promise<void> {
|
|
this.logger.info('Updating storage quota for user...', {
|
|
userId: event.payload.userUuid,
|
|
totalFileByteSize: event.payload.totalFileByteSize,
|
|
codeTag: 'FileQuotaRecalculatedEventHandler',
|
|
})
|
|
|
|
const result = await this.updateStorageQuota.execute({
|
|
userUuid: event.payload.userUuid,
|
|
bytesUsed: event.payload.totalFileByteSize,
|
|
})
|
|
|
|
if (result.isFailed()) {
|
|
this.logger.error('Could not update storage quota', {
|
|
userId: event.payload.userUuid,
|
|
codeTag: 'FileQuotaRecalculatedEventHandler',
|
|
})
|
|
|
|
return
|
|
}
|
|
|
|
this.logger.info('Storage quota updated', {
|
|
userId: event.payload.userUuid,
|
|
totalFileByteSize: event.payload.totalFileByteSize,
|
|
codeTag: 'FileQuotaRecalculatedEventHandler',
|
|
})
|
|
}
|
|
}
|