|
@@ -1,26 +1,32 @@
|
|
import { inject, injectable } from 'inversify'
|
|
import { inject, injectable } from 'inversify'
|
|
import { Logger } from 'winston'
|
|
import { Logger } from 'winston'
|
|
|
|
+import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
|
|
|
+
|
|
import TYPES from '../../../Bootstrap/Types'
|
|
import TYPES from '../../../Bootstrap/Types'
|
|
import { WebSocketsConnectionRepositoryInterface } from '../../WebSockets/WebSocketsConnectionRepositoryInterface'
|
|
import { WebSocketsConnectionRepositoryInterface } from '../../WebSockets/WebSocketsConnectionRepositoryInterface'
|
|
-import { UseCaseInterface } from '../UseCaseInterface'
|
|
|
|
import { AddWebSocketsConnectionDTO } from './AddWebSocketsConnectionDTO'
|
|
import { AddWebSocketsConnectionDTO } from './AddWebSocketsConnectionDTO'
|
|
-import { AddWebSocketsConnectionResponse } from './AddWebSocketsConnectionResponse'
|
|
|
|
|
|
|
|
@injectable()
|
|
@injectable()
|
|
-export class AddWebSocketsConnection implements UseCaseInterface {
|
|
|
|
|
|
+export class AddWebSocketsConnection implements UseCaseInterface<void> {
|
|
constructor(
|
|
constructor(
|
|
@inject(TYPES.WebSocketsConnectionRepository)
|
|
@inject(TYPES.WebSocketsConnectionRepository)
|
|
private webSocketsConnectionRepository: WebSocketsConnectionRepositoryInterface,
|
|
private webSocketsConnectionRepository: WebSocketsConnectionRepositoryInterface,
|
|
@inject(TYPES.Logger) private logger: Logger,
|
|
@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 Result.ok()
|
|
|
|
+ } catch (error) {
|
|
|
|
+ this.logger.error(
|
|
|
|
+ `Error persisting connection ${dto.connectionId} for user ${dto.userUuid}: ${(error as Error).message}`,
|
|
|
|
+ )
|
|
|
|
|
|
- return {
|
|
|
|
- success: true,
|
|
|
|
|
|
+ return Result.fail((error as Error).message)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|