fix: reduce websockets api communication data (#919)

This commit is contained in:
Karol Sójko
2023-11-09 11:44:31 +01:00
committed by GitHub
parent 4ff78452f9
commit c4ae12d53f
8 changed files with 78 additions and 33 deletions
@@ -1,26 +1,32 @@
import { inject, injectable } from 'inversify'
import { Logger } from 'winston'
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
import TYPES from '../../../Bootstrap/Types'
import { WebSocketsConnectionRepositoryInterface } from '../../WebSockets/WebSocketsConnectionRepositoryInterface'
import { UseCaseInterface } from '../UseCaseInterface'
import { AddWebSocketsConnectionDTO } from './AddWebSocketsConnectionDTO'
import { AddWebSocketsConnectionResponse } from './AddWebSocketsConnectionResponse'
@injectable()
export class AddWebSocketsConnection implements UseCaseInterface {
export class AddWebSocketsConnection implements UseCaseInterface<void> {
constructor(
@inject(TYPES.WebSocketsConnectionRepository)
private webSocketsConnectionRepository: WebSocketsConnectionRepositoryInterface,
@inject(TYPES.Logger) private logger: Logger,
) {}
async execute(dto: AddWebSocketsConnectionDTO): Promise<AddWebSocketsConnectionResponse> {
this.logger.debug(`Persisting connection ${dto.connectionId} for user ${dto.userUuid}`)
async execute(dto: AddWebSocketsConnectionDTO): Promise<Result<void>> {
try {
this.logger.debug(`Persisting connection ${dto.connectionId} for user ${dto.userUuid}`)
await this.webSocketsConnectionRepository.saveConnection(dto.userUuid, dto.connectionId)
await this.webSocketsConnectionRepository.saveConnection(dto.userUuid, dto.connectionId)
return {
success: true,
return Result.ok()
} catch (error) {
this.logger.error(
`Error persisting connection ${dto.connectionId} for user ${dto.userUuid}: ${(error as Error).message}`,
)
return Result.fail((error as Error).message)
}
}
}