|
@@ -1,19 +1,18 @@
|
|
import { inject, injectable } from 'inversify'
|
|
import { inject, injectable } from 'inversify'
|
|
-import { Username, Uuid } from '@standardnotes/domain-core'
|
|
|
|
|
|
+import { Result, UseCaseInterface, Username, Uuid } from '@standardnotes/domain-core'
|
|
|
|
|
|
import TYPES from '../../../Bootstrap/Types'
|
|
import TYPES from '../../../Bootstrap/Types'
|
|
import { AnalyticsEntityRepositoryInterface } from '../../Entity/AnalyticsEntityRepositoryInterface'
|
|
import { AnalyticsEntityRepositoryInterface } from '../../Entity/AnalyticsEntityRepositoryInterface'
|
|
-import { UseCaseInterface } from '../UseCaseInterface'
|
|
|
|
import { GetUserAnalyticsIdDTO } from './GetUserAnalyticsIdDTO'
|
|
import { GetUserAnalyticsIdDTO } from './GetUserAnalyticsIdDTO'
|
|
import { GetUserAnalyticsIdResponse } from './GetUserAnalyticsIdResponse'
|
|
import { GetUserAnalyticsIdResponse } from './GetUserAnalyticsIdResponse'
|
|
|
|
|
|
@injectable()
|
|
@injectable()
|
|
-export class GetUserAnalyticsId implements UseCaseInterface {
|
|
|
|
|
|
+export class GetUserAnalyticsId implements UseCaseInterface<GetUserAnalyticsIdResponse> {
|
|
constructor(
|
|
constructor(
|
|
@inject(TYPES.AnalyticsEntityRepository) private analyticsEntityRepository: AnalyticsEntityRepositoryInterface,
|
|
@inject(TYPES.AnalyticsEntityRepository) private analyticsEntityRepository: AnalyticsEntityRepositoryInterface,
|
|
) {}
|
|
) {}
|
|
|
|
|
|
- async execute(dto: GetUserAnalyticsIdDTO): Promise<GetUserAnalyticsIdResponse> {
|
|
|
|
|
|
+ async execute(dto: GetUserAnalyticsIdDTO): Promise<Result<GetUserAnalyticsIdResponse>> {
|
|
let analyticsEntity = null
|
|
let analyticsEntity = null
|
|
if (dto.userUuid) {
|
|
if (dto.userUuid) {
|
|
analyticsEntity = await this.analyticsEntityRepository.findOneByUserUuid(dto.userUuid)
|
|
analyticsEntity = await this.analyticsEntityRepository.findOneByUserUuid(dto.userUuid)
|
|
@@ -22,13 +21,13 @@ export class GetUserAnalyticsId implements UseCaseInterface {
|
|
}
|
|
}
|
|
|
|
|
|
if (analyticsEntity === null) {
|
|
if (analyticsEntity === null) {
|
|
- throw new Error(`Could not find analytics entity for user ${dto.userUuid}`)
|
|
|
|
|
|
+ return Result.fail(`Could not find analytics entity ${dto.userUuid}`)
|
|
}
|
|
}
|
|
|
|
|
|
- return {
|
|
|
|
|
|
+ return Result.ok({
|
|
analyticsId: analyticsEntity.id,
|
|
analyticsId: analyticsEntity.id,
|
|
userUuid: Uuid.create(analyticsEntity.userUuid).getValue(),
|
|
userUuid: Uuid.create(analyticsEntity.userUuid).getValue(),
|
|
username: Username.create(analyticsEntity.username).getValue(),
|
|
username: Username.create(analyticsEntity.username).getValue(),
|
|
- }
|
|
|
|
|
|
+ })
|
|
}
|
|
}
|
|
}
|
|
}
|