refactor
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import type { Logger } from '@core/shared/application';
|
||||
import type { Logger, UseCaseOutputPort, UseCase } from '@core/shared/application';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
export interface GetDashboardDataInput {}
|
||||
|
||||
@@ -9,12 +11,14 @@ export interface GetDashboardDataOutput {
|
||||
totalLeagues: number;
|
||||
}
|
||||
|
||||
export class GetDashboardDataUseCase {
|
||||
export type GetDashboardDataErrorCode = 'REPOSITORY_ERROR';
|
||||
|
||||
export class GetDashboardDataUseCase implements UseCase<GetDashboardDataInput, GetDashboardDataOutput, GetDashboardDataErrorCode> {
|
||||
constructor(
|
||||
private readonly logger: Logger,
|
||||
) {}
|
||||
|
||||
async execute(): Promise<GetDashboardDataOutput> {
|
||||
async execute(input: GetDashboardDataInput = {}): Promise<Result<GetDashboardDataOutput, ApplicationErrorCode<GetDashboardDataErrorCode, { message: string }>>> {
|
||||
try {
|
||||
// Placeholder implementation - would need repositories from identity and racing domains
|
||||
const totalUsers = 0;
|
||||
@@ -29,15 +33,21 @@ export class GetDashboardDataUseCase {
|
||||
totalLeagues,
|
||||
});
|
||||
|
||||
return {
|
||||
const result = Result.ok<GetDashboardDataOutput, ApplicationErrorCode<GetDashboardDataErrorCode, { message: string }>>({
|
||||
totalUsers,
|
||||
activeUsers,
|
||||
totalRaces,
|
||||
totalLeagues,
|
||||
};
|
||||
});
|
||||
return result;
|
||||
} catch (error) {
|
||||
this.logger.error('Failed to get dashboard data', { error });
|
||||
throw error;
|
||||
const err = error as Error;
|
||||
this.logger.error('Failed to get dashboard data', err);
|
||||
const result = Result.err<GetDashboardDataOutput, ApplicationErrorCode<GetDashboardDataErrorCode, { message: string }>>({
|
||||
code: 'REPOSITORY_ERROR',
|
||||
details: { message: err.message ?? 'Failed to get dashboard data' },
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user