fix issues in core
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { Logger, UseCase, UseCaseOutputPort } from '@core/shared/application';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { IPageViewRepository } from '../repositories/IPageViewRepository';
|
||||
|
||||
export interface GetAnalyticsMetricsInput {
|
||||
startDate?: Date;
|
||||
@@ -18,19 +19,23 @@ export type GetAnalyticsMetricsErrorCode = 'REPOSITORY_ERROR';
|
||||
|
||||
export class GetAnalyticsMetricsUseCase implements UseCase<GetAnalyticsMetricsInput, void, GetAnalyticsMetricsErrorCode> {
|
||||
constructor(
|
||||
// private readonly pageViewRepository: IPageViewRepository, // TODO: Use when implementation is ready
|
||||
private readonly logger: Logger,
|
||||
private readonly output: UseCaseOutputPort<GetAnalyticsMetricsOutput>,
|
||||
private readonly pageViewRepository?: IPageViewRepository,
|
||||
) {}
|
||||
|
||||
async execute(input: GetAnalyticsMetricsInput = {}): Promise<Result<void, ApplicationErrorCode<GetAnalyticsMetricsErrorCode, { message: string }>>> {
|
||||
async execute(
|
||||
input: GetAnalyticsMetricsInput = {},
|
||||
): Promise<Result<void, ApplicationErrorCode<GetAnalyticsMetricsErrorCode, { message: string }>>> {
|
||||
try {
|
||||
const startDate = input.startDate ?? new Date(Date.now() - 30 * 24 * 60 * 60 * 1000); // 30 days ago
|
||||
const endDate = input.endDate ?? new Date();
|
||||
|
||||
// TODO: Use pageViewRepository when implemented
|
||||
// const pageViews = await this.pageViewRepository.countByDateRange(startDate, endDate);
|
||||
const pageViews = 0;
|
||||
const pageViews = this.pageViewRepository
|
||||
? (await this.pageViewRepository.findByDateRange(startDate, endDate)).length
|
||||
: 0;
|
||||
|
||||
// Note: additional metrics require dedicated repositories / event sources.
|
||||
const uniqueVisitors = 0;
|
||||
const averageSessionDuration = 0;
|
||||
const bounceRate = 0;
|
||||
|
||||
@@ -50,7 +50,6 @@ export class GetEntityAnalyticsQuery
|
||||
constructor(
|
||||
private readonly pageViewRepository: IPageViewRepository,
|
||||
private readonly engagementRepository: IEngagementRepository,
|
||||
// private readonly snapshotRepository: IAnalyticsSnapshotRepository, // TODO: Use when implementation is ready
|
||||
private readonly logger: Logger
|
||||
) {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user